Author: jisom Date: Thu Jan 12 17:35:40 2006 New Revision: 11140 Modified: trunk/src/classes/resizablestringarray.pmc Log: Added shift_string, delete_keyed, and delete_keyed_int
Modified: trunk/src/classes/resizablestringarray.pmc ============================================================================== --- trunk/src/classes/resizablestringarray.pmc (original) +++ trunk/src/classes/resizablestringarray.pmc Thu Jan 12 17:35:40 2006 @@ -179,8 +179,79 @@ Creates and returns a copy of the array. return copy; } +/* + +=item C<STRING* shift_string()> + +Removes and returns an item from the start of the array. + +=cut + +*/ + + STRING* shift_string () { + INTVAL size; + STRING* value; + + size = PMC_int_val(SELF); + if (size == 0) + internal_exception(OUT_OF_BOUNDS, + "ResizableStringArray: Can't shift from an empty array!"); + + value = DYNSELF.get_string_keyed_int(0); + DYNSELF.delete_keyed_int(0); + return value; + } + +/* + +=item C<void delete_keyed_int(INTVAL key)> + +Converts C<key> to a PMC key and calls C<delete_keyed()> with it. + +=cut + +*/ + + void delete_keyed_int (INTVAL key) { + PMC **data; + INTVAL size; + size = PMC_int_val(SELF); + + INTVAL i; + INTVAL n = PMC_int_val(SELF); + data = PMC_data(SELF); + for (i = key; i < n - 1; ++i) + data[i] = data[i + 1]; + DYNSELF.set_integer_native(size - 1); + } + +/* + +=item C<void delete_keyed(PMC* key)> + +Removes the element at C<*key>. + +=cut + +*/ + + void delete_keyed (PMC* key) { + PMC **data; + INTVAL size; + size = PMC_int_val(SELF); + INTVAL idx = key_integer(INTERP, key); + + INTVAL i; + INTVAL n = PMC_int_val(SELF); + data = PMC_data(SELF); + for (i = idx; i < n - 1; ++i) + data[i] = data[i + 1]; + DYNSELF.set_integer_native(size - 1); + } } + /* =back