Ordered collections: lists and sequences

  • A list is a growable collection, implemented as a linked list. Access and update at the ends is fast, in the middle is slow.

  • A sequence is a growable collection which uses an underlying vector, making a new vector when it fills. Similar to a Smalltalk OrderedCollection.

Ordered collections: lists and sequences

A list is growable collection, implemented using a linked list. It is fast to add and remove objects at either end, but relatively slow to access objects in the middle. Adding and removing in the middle is not supported. Special list messages include addFirst:, addLast:, removeFirst and removeLast.

A sequence is a growable collection, implemented using a vector. When the vector fills, a new, bigger vector is created and substituted. Hence, growing can be expensive when the vector is full. However, access and update is fast. Removing from the middle is slow, as elements have to be shifted to close up the gap. A sequence is analogous to a Smalltalk OrderedCollection.

With the exception of messages like add:, addFirst: and removeFirst:, a sequence behaves similarly to a vector.

[ Previous ] [ Index ] [ Next ]