This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Scheme style auto-resizing hashtable (fwd)


On Sat, 7 Nov 1998, Jay Glascoe wrote:

> 12 essential procedures, not counting the "hash-table''/'v'/'q'/'x'"
> duplication.

<snip>

> hash-table-copy hash-table [key-value-pair-transformer]
>     return a new dictionary with key-value-pairs
>     (key-value-pair-transformer key-value-pair)
>     "key-value-pair-transformer" defaults to
>     (lambda (key-value-pair)
>       (cons (car key-value-pair) (cdr key-value-pair)))

a.k.a. hash-table-map.  I can't imagine why anyone would want a new hash
table where insertion and removal will effect the old hash table.  So...

hash-table-copy hash-table [pair-transformer]
    return a new dictionary with key-value-pairs given by

    (let ((new-pair (lambda (old-pair)
                      (cons (car old-pair) (cdr old-pair)))))
      (pair-transformer new-pair))

    "pair-transformer" defaults to the identity function.
    for efficiency, "pair-transformer" is encouraged to use
    set-c[ad]r!  as many times as it likes.

If a user really wants a shallow copy of the old hash table, well,
they're screwed.

no, just kidding  :)

(list->hash-table (hash-table->list hash-table))

sort of a pig, but it does the job.


	Jay Glascoe
	jglascoe@jay.giss.nasa.gov