NAME
src/pmc/orderedhash.pmc - Ordered Hash
DESCRIPTION
OrderedHash
provide the interfaces of array
and hash
.
Some limitations:
- Keys are always STRING*.
- Values are always PMC*.
To archive ordering for each item we store:
key
value
next
prev
Original key
Original value
Pointer to next item
Pointer to previous item
OrderedHash stores next things:
hash
first
last
Lookup hash for values.
Pointer to first inserted value.
Pointer to last inserter value.
See t/pmc/orderedhash.t for test cases.
Overall design heavily inspired by Tie::StoredOrderHash
.
Methods
static PMC* get_list_item(PARROT_INTERP, PMC *self, INTVAL idx)
Get list_item by indexXXX Can this actually return NULL or not?
static void find_bounds(PARROT_INTERP, PMC *pmc_hash, PMC **first, PMC **last)
Find first/last in cloned/thawed OrderedHashParameter static PMC* box_integer(PARROT_INTERP, INTVAL val)
Helper function to box INTVAL
static PMC* box_number(PARROT_INTERP, FLOATVAL val)
Helper function to box FLOATVAL
void init()
Create new instance of OrderedHash.
void mark()
Marks the OrderedHash as live.
PMC *get_iter()
Return a new iterator
INTVAL elements()
INTVAL get_integer()
FLOATVAL get_number()
Returns the size of the hash.
set_pmc_keyed(PMC *key, PMC *value)
Main set function.
void set_integer_keyed(INTVAL key, INTVAL value)
void set_number_keyed(INTVAL key, FLOATVAL value)
void set_string_keyed(INTVAL key, STRING *value)
Sets the PMC value of the element at index void set_pmc_keyed_str(STRING *key, PMC *val)
Sets the PMC value of the element at index PMC *get_pmc_keyed(PMC *key)
PMC *get_pmc_keyed_int(INTVAL key)
PMC *get_pmc_keyed_str(STRING *key)
STRING *get_string_keyed(PMC *key)
STRING *get_string_keyed_int(INTVAL key)
STRING *get_string_keyed_str(STRING *key)
INTVAL get_integer_keyed(PMC *key)
INTVAL get_integer_keyed_str(STRING *key)
INTVAL get_integer_keyed_int(INTVAL key)
Returns the integer value associated with FLOATVAL get_number_keyed(PMC *key)
FLOATVAL get_number_keyed_int(INTVAL key)
FLOATVAL get_number_keyed_str(STRING *key)
Returns the floating-point value for the element at void set_pmc_keyed_int(INTVAL idx, PMC *val)
void set_integer_keyed_int(INTVAL key, INTVAL value)
void set_number_keyed_int(INTVAL key, FLOATVAL value)
void set_string_keyed_int(INTVAL key, STRING *value)
Sets the PMC value of the element at index void push_float(FLOATVAL value)
void push_integer(INTVAL value)
void push_pmc(PMC *value)
void push_string(STRING *value)
INTVAL exists_keyed(PMC *key)
INTVAL exists_keyed_str(STRING *key)
INTVAL exists_keyed_int(INTVAL key)
INTVAL defined_keyed(PMC *key)
INTVAL defined_keyed_int(INTVAL key)
void delete_keyed(PMC *key)
void delete_keyed_int(INTVAL key)
Deletes the key PMC *clone()
Create a clone of the OrderedHash.
Non-existent keys are compacted.
Accessing the clone via integers has different indices,
if items were deleted.
void visit(PMC *info)
Used during archiving to visit the elements in the hash.
void freeze(PMC *info)
Used to archive the hash.
void thaw(PMC *info)
Used to unarchive the hash.
get_pmc()
Get underlying regular Hash.
Used in UnManagedStruct.
pmc_hash
is Hash,
not OrderedHash
key
to val
.
key
to val
.
key
.
key
.
key
to val
.
The created key = "\1idx".
*key
from the hash.
SEE ALSO
docs/pdds/pdd08_keys.pod.