[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: functional hash operations

From: Christopher Cramer
Subject: Re: functional hash operations
Date: Tue, 31 Dec 2002 18:48:36 -0600
User-agent: Mutt/1.2.5i

On Tue, Dec 31, 2002 at 04:26:53PM -0500, Paul Jarc wrote:
> (define (hash-add table key val)
>   (let ((new-table (list->vector (vector->list table)))
>         (index (hash key (vector-length table))))
>     (vector-set! new-table index `((,key . ,val) . ,(vector-ref table index)))
>     new-table))
> This shares the keys, the values, the association pairs, and the list
> pairs between the two tables.  (BTW, is there a better way to copy a
> vector?)

A better way would be to use vector-move-left! or vector-move-right!:

(define (vector-copy v)
    (let* ((len (vector-length v)) (new (make-vector len)))
        (vector-move-left! v 0 len new 0)

But I hope you aren't copying a hash table in time-critical code to
begin with.

Christopher Cramer <address@hidden> <>
"All you have to do is tell them they are being attacked and denounce the
pacifists for lack of patriotism and exposing the country to danger. It
works the same way in any country." - Hermann Georing, 1946

reply via email to

[Prev in Thread] Current Thread [Next in Thread]