Crate more_collections

source ·
Expand description

More collection types.

§Small* collections

Built on top of the excellent smallvec crate, SmallMap and SmallSet are a Map and Set respectively that are inlined if they contain fewer values than a (statically chosen) capacity C, otherwise they are heap allocated and backed by an IndexMap.

§VecMap

See vec_map for more details.

§Multimap

A collection that maps keys to values, similar to HashMap, but where each key may be associated with multiple values. Multimaps can be visualized as a map from keys to non-empty collections of values:

  • a → 0, 1
  • b → 2

Or, it can be visualized as a collection of key-value pairs:

  • a → 0
  • a → 1
  • b → 2

The multimap API is based on the second form, len() == 3 and keys_len() == 2 for the above example.

NameBehaves asKeys orderValues orderMay contain duplicates
HashSetMultimapHashMap<K,HashSet<V>>Arbitrary orderArbitrary orderNo
HashVecMultimapHashMap<K,Vec<V>>Arbitrary orderInsertion order1Yes
IndexSetMultimapIndexMap<K,IndexSet<V>>Insertion order1Insertion order1No
IndexVecMultimapIndexMap<K, Vec<V>>Insertion order1Insertion order1Yes

§Crate features

All features are disabled by default. The options are:

  • hashsetmultimap
  • hashvecmultimap
  • indexsetmultimap
  • indexvecmultimap

  1. Insertion order is preserved, unless remove() or swap_remove() is called. See more in the IndexMap documentation. 

Re-exports§

Modules§

Macros§

Structs§

  • Multimap implementation that behaves like HashMap<K, HashSet<V>>.
  • Multimap implementation that behaves like HashMap<K, Vec<V>>.
  • Multimap implementation that behaves like IndexMap<K, IndexSet<V>>.
  • Multimap implementation that behaves like IndexMap<K, Vec<V>>.