Struct agb::hash_map::HashMap

source ·
pub struct HashMap<K, V, ALLOCATOR: Allocator = Global> { /* private fields */ }
Expand description

A hash map implemented very simply using robin hood hashing.

HashMap uses FxHasher internally, which is a very fast hashing algorithm used by rustc and firefox in non-adversarial places. It is incredibly fast, and good enough for most cases.

It is required that the keys implement the Eq and Hash traits, although this can be frequently achieved by using #[derive(PartialEq, Eq, Hash)]. If you implement these yourself, it is important that the following property holds:

k1 == k2 => hash(k1) == hash(k2)

It is a logic error for the key to be modified in such a way that the key’s hash, as determined by the Hash trait, or its equality as determined by the Eq trait, changes while it is in the map. The behaviour for such a logic error is not specified, but will not result in undefined behaviour. This could include panics, incorrect results, aborts, memory leaks and non-termination.

The API surface provided is incredibly similar to the std::collections::HashMap implementation with fewer guarantees, and better optimised for the GameBoy Advance.

Implementations§

Creates a HashMap

Creates an empty HashMap with specified internal size. The size must be a power of 2

Creates an empty HashMap which can hold at least capacity elements before resizing. The actual internal size may be larger as it must be a power of 2

Creates an empty HashMap with specified internal size using the specified allocator. The size must be a power of 2

Creates a HashMap with a specified allocator

Returns a reference to the underlying allocator

Creates an empty HashMap which can hold at least capacity elements before resizing. The actual internal size may be larger as it must be a power of 2

Returns the number of elements in the map

Returns the number of elements the map can hold

An iterator visiting all keys in an arbitrary order

An iterator visiting all values in an arbitrary order

An iterator visiting all values in an arbitrary order allowing for mutation

Removes all elements from the map

An iterator visiting all key-value pairs in an arbitrary order

An iterator visiting all key-value pairs in an arbitrary order, with mutable references to the values

Retains only the elements specified by the predicate f.

Returns true if the map contains no elements

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated and the old value is returned. The key is not updated, which matters for types that can be == without being identical.

Returns true if the map contains a value for the specified key.

Returns the key-value pair corresponding to the supplied key

Returns a reference to the value corresponding to the key. Returns None if there is no element in the map with the given key.

Returns a mutable reference to the value corresponding to the key. Return None if there is no element in the map with the given key.

Removes the given key from the map. Returns the current value if it existed, or None if it did not.

Gets the given key’s corresponding entry in the map for in-place manipulation.

Trait Implementations§

Returns the “default value” for a type. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more

An iterator over entries of a HashMap

This struct is created using the into_iter() method on HashMap as part of its implementation of the IntoIterator trait.

The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.