8.45. File tom/MutableArray

class tom.MutableArray

inherits

State supers: Array, MutableIndexed

methods


instance (id)
  withCapacity int cap;

Return a new instance of the receiving class which can hold cap elements without the need for resizing.

instance tom.MutableArray

variables

public int capacity;

The capacity of the array.

methods


void
  add All object;

Store the object at the end in the receiving array. If the receiving array stores unboxed values, the object is queried for its value.


(int, int)
  adjustMutableRange (int, int) (start, len);

Adjust the range (start, len) to fit the capacity of the receiving MutableArray. If len == -1, it is adjusted to fit the capacity.


void
  empty
post
  length == 0;

Empty the receiving array. This frees any storage used by the array to store its elements.


deferred id
  initWithCapacity int capacity;

Initialize the newly allocated receiving object to be able to hold capacity items without needing to resize.


id
  initWith int n
        at pointer addr;

Initialize with the indicated pointer and integer for contents and length. The capacity is set to the length.


deferred void
  insert All object
      at int index
pre
  index >= 0 && index <= length;

Insert the object at the index, shifting the objects at that or a higher index up by 1 position.


deferred Any
  removeAt int index;

Remove the element from index, decreasing the index of all elements after index, and return the element boxed. If the receiving array stores unboxed values, such as integers, the value returned is the element boxed.


void
  removeElementAt int index;

Remove the element from index, decreasing the index of all elements after index.


deferred void
  removeElements (int, int) (start, length);

Remove the length elements from start. If length == -1, all elements from start are removed.


void
  resize int to
pre
  to >= 0;

Adjust the size of the array, filling any newly created entries with the default value for the type (i.e. 0).


deferred void
  resize (int, int) (start, num);

Adjust the size of the array by inserting num new entries at start filling newly created entries with the default values for the type (i.e. 0).


void
  truncate int new_length
pre
  new_length >= 0;

Adjust the length of this array to new_length.


void
  bubbleSortUsingKey selector key
         comparator: selector cmp = selector (int compare All);

Bublesort the receiving array on the key of the contained elements by comparing them using the compare selector.


void
  quickSortUsingKey selector key
        comparator: selector compare = selector (int compare All);

Quicksort the receiving array on the key of the contained elements by comparing them using the compare selector.


id
  initCopy;

In addition to what our super does, adjust our (new) capacity to fit our length.