| parrotcode: Hash table | |
| Contents | C |

src/hash.c - Hash table

A hashtable contains an array of bucket indexes.
Buckets are nodes in a linked list,
each containing a void * key and value.
During hash creation,
the types of key and value as well as appropriate compare and hashing functions can be set.
This hash implementation uses just one piece of malloced memory.
The hash->bs bucket store points to this region.
This hash doesn't move during GC, therefore a lot of the old caveats don't apply.

key_hash_STRINGvalue.
See also string.c.STRING_comparepointer_comparekey_hash_pointercstring_comparekey_hash and compare functions.key_hash_intkey_hash function.int_comparecompare function.parrot_dump_hashparrot_mark_hashhash_thawpinfo is the visit info,
(see include/parrot/pmc_freeze.h>).expand_hashMAXFULL_PERCENT % of N as the number of buckets.
This way,
as soon as we run out of buckets on the free list,
we know that it's time to resize the hashtable. bucket_index = hash(key) % parrot_hash_size
parrot_hash_size (the old parrot_hash_size). In fact, because the hashtable is always a power of two in size, it depends only on the next bit in the hash value, after the ones previously used.->next pointers, and they'll be all over memory.)parrot_new_hashhptr.parrot_new_pmc_hashparrot_new_cstring_hashhptr.parrot_new_hash_xhptr.Hash* is seen, it doesn't get properly marked (only the Hash* buffer is marked, not its contents). By passing the **hptr up to the Hash's init function, the newly constructed PMC is on the stack including this newly constructed Hash, so that it gets marked properly.parrot_new_pmc_hash_xcontainer PMC gets stored in the Hash end the newly created Hash is in PMC_struct_val(container).parrot_new_pointer_hashparrot_new_INTVAL_hashflags can be PObj_constant_FLAG or 0.parrot_hash_sizeparrot_hash_get_idxparrot_hash_get_bucketkey.parrot_hash_getkey or NULL if no bucket is found.parrot_hash_existsparrot_hash_putkey is not copied.parrot_hash_deleteparrot_hash_clonehash to dest.
docs/pdds/pdd08_keys.pod.

Future optimizations:
realloc.)
|
|
|