18.4 Other Collection Types in the Standard Library

Beyond Vec, String, and HashMap, the standard library offers more collections:

  • BTreeMap<K, V>: A balanced tree map with O(log n) operations and sorted keys.
  • HashSet<T> and BTreeSet<T>: Store unique values. HashSet uses hashing (O(1) average), BTreeSet is tree-based (O(log n)) and sorted.
  • VecDeque<T>: A double-ended queue allowing efficient insertion/removal at both ends.
  • LinkedList<T>: A doubly linked list; efficient insertion/removal at known positions, but less cache-friendly than Vec.

All these types are generic, just like Vec<T> and HashMap<K, V>.