Crate kollect

Source
Expand description

§🗂️ kollect

A set of collections optimized for game development usecases.

§Provided Collections

  • LinearMap, useful when you want a collection that behaves as a key-value map but you will only ever have up to a few tens of elements. For small numbers of elements and small size of contained key/value types, this will likely be faster and take up less memory than other map types, but its random access operations have O(len) complexity rather than O(1) as with hash-based maps.

  • UnorderedMap, useful when you want a general-purpose key-value map, you plan to do random access lookup by key more frequently than iteration of the contained elements, and you don’t care about order of those elements.

  • OrderedMap, useful when you want a key-value map including a set order of element pairs, or when you plan to iterate over the contained elements more frequently than you do random access lookup by key.

  • LinearSet, useful in the same situation as LinearMap but when you’re operating on a set of values rather than a map.

  • UnorderedSet, useful when you want set-like operations, will do more random access than iteration, and will fill with a medium to high number of elements.

  • OrderedSet, useful when you want set-like operations and need a defined order of elements, or you plan to iterate over the contained elements more frequently than do random access lookup on them.

§Usage table

Number of elementsAccess patternNeed defined orderChoose
Less than ~128AnyAnyLinearMap/LinearSet
More than ~128More Random AccessNoUnorderedMap/UnorderedSet
More than ~128More IterationNoOrderedMap/OrderedSet
More than ~128AnyYesOrderedMap/OrderedSet

§Specialized hashers

The specialized_hashers module contains some helpful specialized hasher variants that can speed up your hash-based collections when you have knowledge about the keys/elements being used.

For example, if your keys in a map or set are small and primitive-integer-only, then you may want to use a BuildPrimitiveHasher-based alias of one of the hash-based collections (UnorderedPrimitiveMap, etc.).

Alternatively, if you are keying a map or creating a collection of elements which are themselves already a hash value (or which otherwise qualify as NoHashable), then you may want to use one of the BuildNoHashHasher-based aliases of one of the hash-based collections (UnorderedNoHashMap, etc.).

§serde_as_seq for maps

When the serde feature is enabled, there are adapters usable with #[serde(with = "path::to::module")] at kollect::some_map::serde_as_seq which will serialize and deserialize those maps as sequences of (k, v) pair elements rather than as native serde Maps. This is useful with JSON because JSON maps can only have string keys, and if you try to serialize a map to JSON which has a key type that can’t be serialized as a string, the serde JSON impl will simply panic at runtime. Using serde_as_seq will circumvent this issue and allow you to serialize a wider range of key types.

§Feature flags

kollect uses a set of feature flags to optionally reduce the number of dependencies.

The following optional features are available:

NameDescriptionDefault?
speedyEnables speedy support for most typesNo
serdeEnables serde support for most typesNo

Modules§

linear_map
A key-value map specialized for small numbers of elements, implemented by searching linearly in a vector.
linear_set
A set specialized for small numbers of elements, implemented by searching linearly in a vector.
ordered_map
Provides a fast, general purpose, key-value map with a defined order of elements.
ordered_set
Provides a fast, general purpose, deduplicated set type *with a defined order of elements.
specialized_hashers
Contains BuildHashers (which can be used with other hash-based collections provided by this crate) specialized for specific types of elements or situations.
unordered_map
Provides a fast, general purpose, key-value map with no defined order of elements
unordered_set
Provides a fast, general purpose, deduplicated set type with no defined order of elements

Structs§

LinearMap
A map implemented by searching linearly in a vector.
LinearSet
An implementation of a set using the underlying representation of a LinearMap where the value is (). This means the set is effectively a Vec with operations optimized for working on items that function as a set.
OrderedMap
A key-to-value map that has a specified order of contained elements.
OrderedSet
A set that has a specified order of contained elements.
UnorderedMap
A key-to-value map that does not have a specified order of contained elements.
UnorderedSet
A deduplicated set that does not have a specified order of contained elements.

Statics§

FIXED_BUILD_HASHER

Traits§

NoHashable
Used to mark a type as able to be used with a NoHashHasher-based hash map or hash set.

Functions§

get_fixed_hasher
hash_one_fixed

Type Aliases§

BuildHasher
The default hasher used by hash-based collections in this crate.
OrderedNoHashMap
Type-alias of OrderedMap that is useful when you are using keys that are NoHashable
OrderedNoHashSet
Type-alias of OrderedSet that is useful when you are using elements that are NoHashable
OrderedPrimitiveMap
Type-alias of OrderedMap that is useful when you are using small keys consisting of only a few primitive types.
OrderedPrimitiveSet
Type-alias of OrderedSet that is useful when you are using small elements consisting of only a few primitive types.
UnorderedNoHashMap
Type-alias of UnorderedMap that is useful when you are using keys that are NoHashable
UnorderedNoHashSet
Type-alias of UnorderedSet that is useful when you are using elements that are NoHashable
UnorderedPrimitiveMap
Type-alias of UnorderedMap that is useful when you are using small keys consisting of only a few primitive types.
UnorderedPrimitiveSet
Type-alias of UnorderedSet that is useful when you are using small elements consisting of only a few primitive types.