Sequence
A sequence is an ordered but non-indexed collection of objects.
Operations add, remove, and get objects from the ends of a
sequence or at a given Position. The container add operation
adds to the right end and the remove operation splices out the element.
Positions generalize the idea of pointer into a sequence. A position
can be obtained at the start or end of a sequence, or for the current
position of an iterator. An element can be added at a position,
pushing the elements to the right or left to make room. The element
at a position can be retrieved or removed. Finally, a sequence can
return the next or previous position from a given position.
Sequence iterators offer
functionality in addition to the basic iterator functionality.Implementations:
- Sequence_CircList
A circular doubly-linked list of
elements. Only works for pointer types.
- Sequence_Linked
A simple doubly-linked list of
elements. Only works for pointer types.
Member functions:
- add : Sequence . T . Position . int push_dir -> void
Adds the element at the position, pushing the current element toward
the front (push_dir = -1) or back (push_dir = 1).
- add_extreme : Sequence . T . int side -> void
Adds
the element at the front (side = -1) or back (side = 1).
- advance : Sequence . Position . int dir -> Position
Returns the position next to the given position in the given
direction: toward the front (dir = -1) or back (side = 1).
- extreme : Sequence . int side -> T
Returns the element at
the front (side = -1) or back (side = 1).
- new_iterator : Sequence . int dir -> Iterator
Returns an iterator initialized to proceed from back to front (dir =
-1) or front to back (dir = 1).
- new_iterator : Sequence . Position . int dir -> Iterator
Allocates and returns an iterator initialized to proceed from the
position to front (dir = -1) or to back (dir = 1). The receiver is
responsible for deallocation.
- new_position : Sequence . int side -> Position
Returns the position for the front (side = -1) or back (side = 1) of
the sequence.
- remove : Sequence . Position -> void
Removes the
element at the position, closing the hole. The position should not be
used after this operation.
- remove_extreme : Sequence . int side -> void
Removes the
element at the front (side = -1) or back (side = 1).
- retrieve : Sequence . Position -> T
Returns the
element at the position in the sequence, which must be valid.
- valid : Sequence . Position -> bool
Indicates whether
or not the position references a member of the sequence.