8.81. File tom/collections

class tom.Collection

inherits

State supers: State, Conditions, Copying, Enumerable

instance tom.Collection

methods


boolean
  dump_simple_p;

Return YES.


void
  do Block block;

Evaluate the block for each object element in this Collection. Subclasses can provide a faster implementation.


boolean
  equal id other;

Two collections consider themselves equal if they are the same object or when their elements are equal.


void
  freeze;

Make the receiving collection immutable. This is irreversible. It is a no-op for immutable collections.


Collection
  frozen;

Return self if this is a non-mutable Collection. Otherwise, return a non-mutable collection with the same contents.


Any
  member All object;

Return the element contained in this collection, which is equal to the object. The default implementation by Collection visits the elements using an enumerator.


Any
  memq All object;

Like member, but the element is identified on reference equality.


deferred int
  length;

Return the number of elements in this Collection.


void
  makeElementsPerform Invocation invocation;

Fire the invocation at the elements contained in the receiving collection.


void
  makeElementsPerform selector message;

Send the argumentless message to the elements contained in the receiving collection.


void
  makeElementsPerform selector message
                 with All argument;

Send the message with the object argument to the elements contained in the receiving collection.


boolean
  mutable;

A Collection is not mutable.


void
  passElementsTo Invocation inv;

Fire the invocation repeatedly, each time with the next object from the collection completing the invocation.


OutputStream
  write OutputStream s;

Undocumented.

class tom.MutableCollection

inherits

State supers: Collection

instance tom.MutableCollection

methods


deferred void
  add All object;

Undocumented.


void
  addElementsFrom Enumerable other;

Undocumented.


void
  addElementsFromEnumerator Enumerator e;

Undocumented.


deferred void
  empty;

Remove all elements from the receiving collection.


deferred void
  freeze;

Force freeze to be undefined since each particular subclass must itself implement it.


id (self)
  initWithEnumerator Enumerator e;

Initialize by feeding self the elements from the enumerator.


boolean
  mutable;

A MutableCollection is mutable.

class tom.Keyed

A Keyed Collection stores elements on a key.

inherits

State supers: Collection

instance tom.Keyed

methods


deferred Any
  at All key
pre
  key != nil;

Undocumented.


deferred Enumerator
  keyEnumerator;

Return an enumerator on the keys of this mapped collection.


Any
  member All object;

Member for a Keyed collection can be implemented efficiently.


Any
  memq All object;

Like member, but the element is identified on reference equality. This is a less-efficient abstract implementation.

class tom.MutableKeyed

inherits

State supers: Keyed, MutableCollection

instance tom.MutableKeyed

methods


deferred void
  add All object;

Add the object.


deferred void
  remove All object;

Remove the object.


void
  removeElementsFrom Collection c;

Remove all the objects contained in the collection c.


void
  removeElementsFromEnumerator Enumerator e;

Undocumented.


void
  keepElementsFrom Collection c;

Remove all the objects not contained in the collection c, i.e., change the receiving collection into the result of intersecting self and c.

Keyed collections that can not handle losing elements while being enumerated must reimplement this. There is no method keepElementsFromEnumerator because set intersection is not meaningful with an arbitrary enumerator.


Indexed
  allKeys;

All the keys in a convenient format.

class tom.Mapped

A Mapped Collection is a Keyed collection which stores (key, value) associations.

inherits

State supers: Keyed

instance tom.Mapped

methods


void
  doKeys Block block;

Evaluate the block for each key. Subclasses can provide a faster implementation.


deferred MapEnumerator
  valueEnumerator;

Return a MapEnumerator on the values of this Mapped collection.


boolean
  equal id other;

Check for equality, checking not only the values, but also the keys.


deferred Enumerator
  keyEnumerator;

Return an Enumerator on the keys of this Mapped collection.

class tom.MutableMapped

inherits

State supers: Mapped, MutableKeyed

variables

const MAPPED_KEEP = 0;

Directives to guide addPairsFrom.

const MAPPED_ERROR = 1;

const MAPPED_CLOBBER = 2;

instance tom.MutableMapped

methods


void
  add All value;

Add a new pair, using the value as the value and the key.


deferred void
  set All value
   at All key
pre
  key != nil && value != nil;

Undocumented.


void
   addPairsFrom Mapped m
  onContention: int action = MAPPED_KEEP;

Add pairs from another Mapped collection. The optional onContention parameter specifies whether or not pairs which have contending keys should keep the value currently in self, overwrite (clobber) the value currently in self with the value in m, or raise a type-condition Condition.


Indexed
  allValues;

Return all values in an Indexed format.

class tom.Ordered

An Ordered Collection maintains its elements in a specific order, though the time complexity or retrieving the nth object not necessarily independent of n.

inherits

State supers: Collection

instance tom.Ordered

methods


(int, int)
  adjustRange (int, int) (start, len);

Adjust the range (start, len) to fit the length of the receiving Indexed collection.


Any
  at int index
pre
  index >= 0 && index < [self length];

Return the element at index. If the receiving collection stores unboxed values, such as integers, the value returned is the element boxed. Returns nil on index overflow (precondition should whine about it, though - nil may only be returned if [self length] is bugged).


byte
  at int index;

Return the byte value of the element at index. If the receiving collection stores objects, the byteValue of the element retrieved is actually returned.


char
  at int index;

The following all follow the basic type at index stanza.


int
  at int index;

Undocumented.


long
  at int index;

Undocumented.


float
  at int index;

Undocumented.


double
  at int index;

Undocumented.


int
  indexOf All element;

Return the index of the first element, or -1 if it could not be found.


int
  indexOfIdentical All element;

Return the index of the first identical element, or -1 if it could not be found.

class tom.MutableOrdered

inherits

State supers: Ordered, MutableCollection

instance tom.MutableOrdered

methods


deferred void
  set All object
   at int index;

Store the object at index in the receiving collection.


deferred void
  swap (int, int) (i, j);

Swap the elements at the indices i and j.


void
  reverse (int, int) (start, len);

Reverse the elements in the range starting at start, with length len.


void
  reverse;

Reverse the entire collection.


deferred void
  removeElementAt int index;

Remove the element at index, decreasing by 1 the indices of the elements further in the collection.


void
  removeElement All element;

Remove the first occurence of element.


void
  removeIdenticalElement All element;

Remove the first occurence of the identical element.

class tom.Indexed

An Indexed Collection maintains an association between integer indices and the objects it contains, with the promise that retrieving an object through the index is O(1) in time complexity.

inherits

State supers: Ordered

instance tom.Indexed

methods


void
  do Block block;

Evaluate the block for each object element in this Indexed.


dynamic
  elements;

Extract the elements from the receiving collection, as indicated by the return type. The number of elements in the collection must match the number of expected elements.


dynamic
  elements (int, int) (start, num);

Like elements, but extract only the num elements starting at index start.


Enumerator
  enumerator;

Return an Enumerator on this Indexed.


boolean
  equal id other;

A faster implementation than the one inherited from Collection.


int
  indexOf All element;

Return the index of the first element, or -1 if it could not be found.


int
  indexOfIdentical All element;

Return the index of the first identical element, or -1 if it could not be found.


void
  makeElementsPerform Invocation inv;

A faster implementation than the one inherited from Collection, without using an Enumerator.


void
  makeElementsPerform selector message;

Likewise.


void
  makeElementsPerform selector message
                 with All argument;

Likewise.


void
  passElementsTo Invocation inv;

Likewise.

class tom.MutableIndexed

inherits

State supers: Indexed, MutableOrdered

instance tom.MutableIndexed

class tom.IndexedEnumerator

The IndexedEnumerator enumerates any Indexed collection, returning the elements boxed.

inherits

State supers: State, Enumerator

methods


instance (id)
  with Indexed indexed;

Undocumented.

instance tom.IndexedEnumerator

variables

int next;

The index of the next element to be returned.

int num;

The index one beyond the last element to be returned.

Indexed indexed;

The actual indexed collection.

methods


id (self)
    init Indexed a
  start: int start = 0
  length int length;

Designated initializer.


(boolean, Any)
  next;

Undocumented.


(boolean, byte)
  next;

All these next methods are not really necessary, as they are provided by the Enumerator behaviour. However, binding them here directly greatly enhances speed and reduces memory requirements for non-object indexeds, which now also do not need their own enumerator to obtain speed.


(boolean, char)
  next;

Undocumented.


(boolean, int)
  next;

Undocumented.


(boolean, long)
  next;

Undocumented.


(boolean, float)
  next;

Undocumented.


(boolean, double)
  next;

Undocumented.