Expand description
§LinkedHashMap
A hash map that maintains insertion order and supports efficient
O(1) push/pop from both the front and the back, similar to VecDeque.
§Design
Each key-value pair lives in a heap-allocated node. The nodes form a
doubly-linked list that tracks insertion order. A HashMap<K, NonNull<Node<K, V>>>
gives O(1) lookup by key. Because all node pointers are owned by the map and the
HashMap only stores raw pointers (never moves the pointed-to memory), pointer
stability is guaranteed as long as the map is alive and the entry is not removed.
head ⟷ node_A ⟷ node_B ⟷ node_C ⟷ tail (sentinel nodes)
↑ ↑ ↑
HashMap entries (key -> *mut Node)The head and tail fields are sentinel nodes that never hold real data.
Their key / value are never read; they merely anchor the list so that
every “real” node always has both a prev and a next, eliminating many
Option branches in the hot path.
§Ordering contract
LinkedHashMap::insert_back and LinkedHashMap::insert_front preserve
the position of an existing key: only the value is updated in-place. Use
LinkedHashMap::move_to_back / LinkedHashMap::move_to_front to
explicitly reorder an entry.
Re-exports§
pub use iter::Drain;pub use iter::IntoIter;pub use iter::Iter;pub use iter::IterMut;pub use iter::Keys;pub use iter::Values;pub use iter::ValuesMut;
Modules§
- iter
- Iterator types produced by
LinkedHashMap.
Structs§
- Linked
Hash Map - A hash map that preserves insertion order and exposes a
[
VecDeque]-like API with [insert_back], [insert_front], [pop_front], [pop_back], [front], and [back]. - Linked
Hash Set - A hash set that preserves insertion order and exposes a
VecDeque-like API withinsert_back,insert_front, [pop_front], and [pop_back]. - Occupied
Entry - A view into an occupied entry in a
LinkedHashMap. - SetDrain
- Draining iterator - removes and yields every element in insertion order, leaving the set empty.
- SetInto
Iter - Consuming iterator - yields every element in insertion order.
- SetIter
- Iterator over
&Telements in insertion order. - Vacant
Entry - A view into a vacant entry in a
LinkedHashMap.
Enums§
- Entry
- A view into a single entry in a map, similar to
std::collections::hash_map::Entry.