NAME

src/pmc/resizablepmcarray.pmc - ResizablePMCArray PMC

DESCRIPTION

This class, ResizablePMCArray, implements an resizable array which stores PMCs. It changes values into Integer, Float, or String PMCs as appropriate.

Resize thresholds steps are 8 and 4096. Between 8b and 4K resize it overallocates by factor 1.5, over 4K it aligns up to the next 4K block.

We use now the faster nqp/qrpa model with O(1) shift/unshift ops, by moving an extra offset index, with 8 slots reserve. See #1152

Internal Functions

static void do_shift(PARROT_INTERP, Parrot_ResizablePMCArray_attributes *data)
Removes and returns an item from the start of the array.
static void do_unshift(PARROT_INTERP, PMC *arr, PMC *val)
Adds an item at the start of the array. If offset == 0 moves the whole rest of the array around.

Vtable Functions

void init_int(INTVAL size)
Initializes the array.
void set_integer_native(INTVAL size)
Resizes the array to size elements.
FLOATVAL shift_float()
INTVAL shift_integer()
PMC *shift_pmc()
STRING *shift_string()
Removes and returns an item from the start of the array.This throws an OUT_OF_BOUNDS exception if the array is already empty, unlike the perl5 and perl6 shift operator.
PMC *get_pmc_keyed_int(INTVAL key)
Returns the PMC value of the element at index key.
void set_pmc_keyed_int(INTVAL key, PMC *src)
Sets the PMC value of the element at index key to *src.
void set_pmc_keyed(PMC *key, PMC *src)
Sets the PMC value of the element keyed by key to *src.
void delete_keyed_int(INTVAL key)
void delete_keyed(PMC *key)
Delete the element at index key and shift the rest to the left.
INTVAL exists_keyed_int(INTVAL key)
INTVAL exists_keyed(PMC *key)
Returns TRUE is the element at key exists; otherwise returns false.
INTVAL defined_keyed_int(INTVAL key)
Returns TRUE is the element at key is defined; otherwise returns false.
void push_float(FLOATVAL value)
void push_integer(INTVAL value)
void push_pmc(PMC *value)
void push_string(STRING *value)
Extends the array by adding an element of value *value to the end of the array.
INTVAL pop_float()
INTVAL pop_integer()
PMC *pop_pmc()
STRING *pop_string()
Removes and returns the last element in the array.This throws an OUT_OF_BOUNDS exception if the array is already empty, unlike the perl5 and perl6 shift operator.
void unshift_float(FLOATVAL value)
void unshift_integer(INTVAL value)
void unshift_pmc(PMC *value)
void unshift_string(STRING *value)
Extends the array by adding an element of value *value to the begin of the array.
void mark(void)
Mark the array.
PMC *clone()
Creates and returns a copy of the array.
STRING *get_repr()
Returns the Parrot string representation of the ResizablePMCArray.
void splice(PMC *from, INTVAL offset, INTVAL count)
Replaces count elements starting at offset with the elements in from.Note that the from PMC can be of any of the various array types.
void visit(PMC *info)
This is used by freeze/thaw to visit the contents of the array.*info is the visit info, (see include/parrot/pmc_freeze.h).
void freeze(PMC *info)
Used to archive the array.
void thaw(PMC *info)
Used to unarchive the array.

Methods

METHOD append(PMC *other)
Append the other array to this array.
METHOD PMC* shift()
METHOD PMC* pop()
Method forms to remove and return a PMC from the beginning or end of the array.
METHOD unshift(PMC* value)
METHOD push(PMC* value)
Method forms to add a PMC to the beginning or end of the array.
METHOD sort(PMC *cmp_func)
Sort this array, optionally using the provided cmp_func
METHOD reverse()
Reverse the contents of the array.

Auxiliar functions

static void do_shift(PARROT_INTERP, PMC *arr)
Common part for all shift operations.
static void do_unshift(PARROT_INTERP, PMC *arr, PMC *val)
Common part for all unshift operations.
static void throw_shift_empty(PARROT_INTERP)
static void throw_pop_empty(PARROT_INTERP)
Throws with the appropriate message.

See also

docs/pdds/pdd17_basic_types.pod.