18.7 Selecting the Appropriate Collection
When deciding which collection to use, consider:
- Random integer indexing needed?
Use aVec<T>. - Dynamically growable text?
UseString. - Fast lookups with arbitrary keys?
Use aHashMap<K, V>. - Key-value pairs in sorted order?
UseBTreeMap<K, V>. - Need a set of unique items?
UseHashSet<T>orBTreeSet<T>. - Frequent push/pop at both ends?
UseVecDeque<T>. - Frequent insertion/removal in the middle at known locations?
UseLinkedList<T>, but confirm it’s really necessary (aVec<T>can still be surprisingly efficient).