Guile Mailing List Archive

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

Re: table vs hash-table



On Mon, 23 Nov 1998 roland.kaufmann@space.at wrote:

<says, in a rather round about way,  ;)
 that RScheme's "hash-table"s are called "table"s>

Yes, and Dylan uses "table" as well.  The logical progression from
"hash-table" to just "table" is that my latest fury of testing involved
much monkeying about with the REPL;  I basically got tired of typing
"hash-" a jillion times over.

> Constructor:
>   (make-table test-fn hash-fn) => table
> 
> Read access:
>   (table-lookup table key) => value(1)
> 
> Write access:
>   (table-insert! table key value) => prev-value
> 
>   (table-remove! table key) => value
> 
> others:
>   (table-size table) => integer
> 

wow, I never really looked at RScheme's table oriented procedures.  I have
all of those verbatim, but "make-table" comes in four flavors:
"make-table[vqx]?", of which only "make-tablex" accepts more than zero
arguments: (make-tablex user-equal? user-hasher)

The fact is that, e.g. calling "scm_equal_p" internally is much faster
than "scm_apply(user_equalp, equalp_args, SCM_EOL)" so the table
constructed by

(define mytable (make-table))

is a good deal faster (~20-30%, at insertion/lookup/deletion, YMMV) than
this table

(define mytable (make-tablex equal? hasher))

> (key-sequence table)   => list
> (value-sequence table) => list
> 

I think a general "table->list" is more flexible.

>   (table-for-each table proc)
> 
>   Where proc takes 3 arguments: hash-code, key and value

Why on earth expose the user to the "hash-code"?  In case the keys are
substantially complex objects?  Also, if I may quote a wise man: 

On Fri, 20 Nov 1998, Obi-Wan "Ben" Kenobi wrote:

>       "map" and "for-each" are standard fare for functional
>     languages.  Think of "table-map" as a procedure object
>     oriented method; so the procedure "pair-transformer"
>     belongs in front.


              Jay Glascoe
           original author of
         "The $ICPyramid Scheme"
	jglascoe@jay.giss.nasa.gov


PS: I'll be on vacation for a week, so no more posts/replies from me
until I get back.  Bye bye, Guile.


Guile Home | Main Index | Thread Index