This is the mail archive of the guile@sourceware.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: A few minor hash questions.


Rob Browning <rlb@cs.utexas.edu> writes:

> I've got a couple of hash table questions that don't seem to be
> answered in guile-ref.
> 
> First of all, what's legitimate for a hash table's format?  Are you
> supposed to allocate a vector of an "appropriate size"?  Something
> like (make-vector 17)?  If so, is there an appropriate default value,
> or is just letting the empty buckets be #<unspecified> OK?

Use make-hash-table, of course :)

> Also, do you have to stick with one pair of matched setters/getters
> for a given hash?  i.e. if you use hashq-set! to build the table, do
> you have to use hashq-ref to access it?  I would have expected
> hash-ref to have worked too, since equal? is a superset of eq?, but it
> doesn't appear to:

While it is true that equal? -> eq?, and in most places you can use
equal? instead of eq? (i.e. memq -> member, assq -> assoc), hash
tables are a special case, since you can't actually see the objects
inside the hash. So, in order to generate the same hash value for
objects that are equal?, you have to consider all the information that
can make an object equal? to another (in strings, for example, this
means having the same length and contents); this is a different
requirement from eq?, which requires that the objects being compared
are actually the same object (this is usually implemented by using the
address of the object mod table-size). Unless by fluke, these are not
likely to be the same (the address of the object having nothing
whatsoever to do with the contents).

The comparison method being used should really be a property of the
hash-table at creation time, though (the way cl does it; saves all
kinds of hassle :).

-- 
Greg

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