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.
static size_t key_hash_STRING
value
.
See also string.c.static int STRING_compare
static int pointer_compare
static size_t key_hash_pointer
static size_t key_hash_cstring
static int cstring_compare
key_hash
and compare
functions.size_t key_hash_int
key_hash
function.int int_compare
compare
function.void parrot_dump_hash
void parrot_mark_hash
static void hash_thaw
pinfo
is the visit info,
(see include/parrot/pmc_freeze.h>).static void hash_freeze
void parrot_hash_visit
static void expand_hash
MAXFULL_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.)void parrot_new_hash
hptr
.void parrot_new_pmc_hash
void parrot_new_cstring_hash
hptr
.static Hash *create_hash
void parrot_hash_destroy
void parrot_chash_destroy
void parrot_new_hash_x
hptr
.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.void parrot_new_pmc_hash_x
container
PMC gets stored in the Hash end the newly created Hash is in PMC_struct_val(container).void parrot_new_pointer_hash
PMC *Parrot_new_INTVAL_hash
flags
can be PObj_constant_FLAG
or 0.INTVAL parrot_hash_size
void *parrot_hash_get_idx
HashBucket *parrot_hash_get_bucket
key
.void *parrot_hash_get
key
or NULL
if no bucket is found.INTVAL parrot_hash_exists
HashBucket *parrot_hash_put
key
is not copied.void parrot_hash_delete
void parrot_hash_clone
hash
to dest
.docs/pdds/pdd08_keys.pod.
Future optimizations:
realloc
.)
|