HP Integrity NonStop H-Series User Manual
Page 50
![background image](/manuals/396950/50/background.png)
Is the collection indexed? That is, can the collection be viewed as a series of key/value pairs?
If the keys are integers between 0 and some upper limit, a
vector
or
deque
should be employed.
If, on the other hand, the key values are some other ordered data type (such as characters,
strings, or a user-defined type), the
map
container can be used.
Can values be related to each other?
All values stored in any container provided by the standard library must be able to test for
equality against another similar value, but not all need to recognize the relational less-than
operator. However, if values cannot be ordered using the relational less-than operator, they
cannot be stored in a
set
or a
map
.
Is finding and removing the largest value from the collection a frequent operation?
If the answer is "yes," the priority queue is the best data structure to use.
At what positions are values inserted into or removed from the structure?
If values are inserted into or removed from the middle, then a
list
is the best choice. If values
are inserted only at the beginning, a
deque
or a list is the preferred choice. If values are inserted
or removed only at the end, a
stack
or
queue
may be a logical choice.
Is a frequent operation the merging of two or more sequences into one?
If so, a
set
or a
list
would seem to be the best choice, depending whether the collection is
maintained in order. Merging two sets is a very efficient operation. If the collections are not
ordered, but the efficient splice() member function from class list can be used, then the list data
type is to be preferred, since this operation is not provided in the other containers.
In many situations any number of different containers may be applicable to a given problem. In
such cases one possibility is to compare actual execution timings to determine which alternative
is best.