STXXL
1.4-dev
|
This page introduces into the stxxl::sequence container (to learn more about the structure of stxxl::sequence, see section stxxl::sequence).
In reality, the STXXL sequence container is a STXXL deque container (see Deque) without random access. Deque stands for "double-ended-queue", that means elements can be accessed, inserted and deleted on both ends of the data structure. Consequently both containers are quite similar - however, the usage varies.
To create an empty stxxl::sequence object with own write and prefetch block pool, only the data value type must be specified:
Inserting elements is possible at the start (by calling the push_front() function) as well as the end (by calling the push_back() function) of the deque (equal to STXXL Deque)
To return a reference to the element at the start of the sequence, call front(), to return a reference to the elemtent at the end of the sequence, call back() on a deque instance.
Due to the fact that the sequence container does not support random access, the sequence can only be accessed in an I/O-efficient way by iterating using streams: either from front to back or in reverse. For this purpose, the sequence provides the public member functions get_stream() and get_reverse_stream().
The preincrement operator ++ let the stream point to the next element in the sequence (depending on the stream direction). Accessing an element the iterator points to is possible by using the prefixed * operator. To check if the end of the sequence container is reached by the stream, the empty() function returns true in such a case. Note that the stream is immutable and therefore read-only, so you can't modify it's members. The subsequent examples illustrate the usage.
The forward iterator moves from back to front and may be used as follows:
The reverse iterator moves from back to front and may be used as follows:
Removing elements is possible at both endings of the sequence by using pop_front() and pop_back():
To determine the size (i.e. the number of elements) of an instance, call size():
To check if the sequence is empty, call empty() which returns true if the sequence is empty:
(See examples/containers/sequence1.cpp for the sourcecode of the following example).