NICHOLAS SHAW

Overview of rust collections and sequences

This is a loose summary of the Rust std::collections documentation formatted for personal reference. Rust offers a range of collection types for different use cases. Reading through the lines in the documentation the underlying theme is the following:

Starting with Vec or HashMap is almost always good enough until you know more about your performance and needs.

CollectionDescriptionUse
VecA continuous array. Similar to a Python List- Resizable, heap allocated array or stack.
- Item properties unimportant
- Append to end of in order sequence
VecDequeA double ended growable queue- Insertion at front end back of sequence.
- Otherwise same use properties as Vec
LinkedListA doubly linked list- Efficient split and append of lists
- Avoid amortisation of Vec and VecDeque
HashMapSimilar to Python Dictionary- Associate keys with values i.e. a cache
BTreeMapAn ordered HashMap.- Need key value pairs with functionality for range slicing, get largest/smallest, and filtering
HashSetSimilar to Python Dictionary with only Hashed keys.- Hold unique keys i.e. values seen before
BTreeSetAn ordered HashSet.- Need unique keys with functionality for range slicing, get largest/smallest, and filtering
BinaryHeapA max value priority queue.- Storing largest or highest priority item i.e. a scheduler