NAME ^

languages/pipp/src/pipp_hash.c - core functions and data structs for the PHPArray PMC

DESCRIPTION ^

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 type of the value can be set. All keys are stored as STRINGs.

Initialization and Finalization Functions ^

PippHashTable *pipp_hash_create(PARROT_INTERP, UINTVAL size)

Create and initialize a new PippHash with at least size buckets.

void pipp_hash_destroy(PARROT_INTERP, PippHashTable *ht)

Non-recursively free all memory used by this PippHash.

void pipp_hash_empty(PARROT_INTERP, PippHashTable *ht)

Delete all items from this PippHash, leaving the size unchanged.

Debugging Functions ^

void pipp_hash_sanity_check(PARROT_INTERP, PippHashTable *ht)

Iterate through the PippHash, making sure that everything's sane. This function is intended only for internal debugging. If anything's goofy, an exception with a descriptive message is thrown.

Miscellaneous Housekeeping Functions ^

void pipp_hash_renumber(PARROT_INTERP, PippHashTable *ht)

Renumber all numerically-indexed elements of this PippHash, starting from 0. Numbering is done according to insertion order.

void pipp_hash_rehash(PARROT_INTERP, PippHashTable *ht)

Recalculate the hash of each element, potentially placing it in another bucket. This is used when a PippHash grows and has its hashMask changed.

void pipp_hash_resize(PARROT_INTERP, PippHashTable *ht, INTVAL new_size)

Increase the capacity and number of buckets of this PippHash. Resizing implies rehashing.

Hash Manipulation Functions ^

PippBucket *pipp_hash_get_bucket(PARROT_INTERP, PippHashTable *ht, STRING *key)

If there is a bucket with a the key key, return a pointer to it. Otherwise return NULL.

PMC *pipp_hash_get(PARROT_INTERP, PippHashTable *ht, STRING *key)

If there is a bucket with a the key key, return the value of that bucket. Otherwise return NULL.

PippBucket *pipp_hash_put(PARROT_INTERP, PippHashTable *ht, STRING *key, PMC *p_val)

Store p_val, indexed by key, in the hash. Return the bucket where p_val was stored.

PippBucket *pipp_hash_find(PARROT_INTERP, PippHashTable *ht, STRING *key)

If there is a bucket with a the key key, return 1. Otherwise return 0.

void pipp_hash_delete(PARROT_INTERP, PippHashTable *ht, STRING *key)

If there's a bucket in this hash with the key key, it is deleted. If there's no matching bucket, nothing happens.

Deque Functions ^

PippBucket *pipp_hash_push(PARROT_INTERP, PippHashTable *ht, PMC *p_val)

Append a bucket with p_val to the PippHash. Its index will be determined by the value of ht->nextIndex. Pushing onto a PippHash does *not* affect internalPointer.

PMC *pipp_hash_pop(PARROT_INTERP, PippHashTable *ht)

Delete the element at the end of this hash, returning its value. Popping from a PippHash also resets internalPointer to point at the first element of the array.

PippBucket *pipp_hash_unshift(PARROT_INTERP, PippHashTable *ht, PMC *p_val)

Prepend a bucket with p_val to the PippHash. Its index will be 0 and all other numerically indexed elements will be renumbered according to insertion order. Unshifting also points internalPointer at the first element.

PMC *pipp_hash_shift(PARROT_INTERP, PippHashTable *ht)

Delete the element at the beginning of this hash, returning its value. This also resets internalPointer to point at the first element of the resulting hash.

Freeze/Thaw Helper Functions ^

void pipp_hash_visit(PARROT_INTERP, PippHashTable *ht, visit_info *info)

Dispatch a call to VTABLE_visit to the appropriate internal function.

void pipp_hash_freeze(PARROT_INTERP, PippHashTable *ht, visit_info *info)

Do most of the actual work of serializing this PippHash into info.

void pipp_hash_thaw(PARROT_INTERP, PippHashTable *ht, visit_info *info)

Unserialize this PippHash into info.

Miscellaneous Helper Functions ^

PippIsInt *pipp_hash_get_intval(PARROT_INTERP, STRING *key)

If s looks like an INTVAL (i.e. /^([-]?[1-9][0-9]|0)*$/) and doesn't cause an overflow, return a PippIsInt where p-intval> contains the INTVAL and p-isInt> is true. Otherwise, return a PippIsInt where p-isInt> is false and p-intval> is undefined.


parrot