Hashx

1 view
Skip to first unread message

In Libman

unread,
Aug 5, 2024, 11:39:09 AM8/5/24
to quicongthecar
Likethe association list functions, the hash table functions come inseveral varieties, according to the equality test used for the keys.Plain hash- functions use equal?, hashq-functions use eq?, hashv- functions use eqv?, andthe hashx- functions use an application supplied test.

Hash tables are implemented as a vector indexed by a hash value formedfrom the key, with an association list of key/value pairs for eachbucket in case distinct keys hash together. Direct access to thepairs in those lists is provided by the -handle- functions.


When the number of entries in a hash table goes above a threshold, thevector is made larger and the entries are rehashed, to prevent thebucket lists from becoming too long and slowing down accesses. When thenumber of entries goes below a threshold, the vector is shrunk to savespace.


When size is given, the table vector will still grow and shrinkautomatically, as described above, but with size as a minimum.If an application knows roughly how many entries the table will holdthen it can use size to avoid rehashing when initial entries areadded.


Note that hashq and hashv may use internal addresses ofobjects, so if an object is garbage collected and re-created it canhave a different hash value, even when the two are notionallyeq?. For instance with symbols,


Apply proc to the entries in the given hash table. Eachcall is (proc key value). hash-map->listreturns a list of the results from these calls, hash-for-eachdiscards the results and returns an unspecified value.


Calls are made over the table entries in an unspecified order, and forhash-map->list the order of the values in the returned list isunspecified. Results will be unpredictable if table is modifiedwhile iterating.


Accumulate a result by applying proc to the elements of thegiven hash table. Each call is (proc keyvalue prior-result), where key and value arefrom the table and prior-result is the return from theprevious proc call. For the first call, prior-result isthe given init value.

3a8082e126
Reply all
Reply to author
Forward
0 new messages