Struct idmap::IdMap[][src]

pub struct IdMap<K: IntegerId, V, T: EntryTable<K, V> = DenseEntryTable<K, V>> { /* fields omitted */ }
Expand description

A map of mostly-contiguous IntegerId keys to values, backed by a Vec.

This is parametric over the type of the underlying EntryTable, which controls its behavior By default it’s equivalent to an OrderedIdMap, though you can explicitly request a DirectIdMap instead.

From the user’s perspective, this is equivalent to a nice wrapper around a Vec<Option<(K, V)>>, that preserves insertion order and saves some space for missing keys. More details on the possible internal representations are documented in the OrderedIdMap and DirectIdMap aliases.

Implementations

Create a new direct IdMap.

This stores its entries directly in a Vector

Create new direct IdMap, initialized with the specified capacity

Because a direct id map stores its values directly, the capacity hints at the maximum id and not the length

Create an empty IdMap using a DenseEntryTable and OrderedIdTable

Create an IdMap with the specified capacity, using an OrderedIdTable

Create an empty IdMap with a custom entry table type.

Create a new IdMap with the specified capacity but a custom entry table.

If this map is empty

The length of this map

This doesn’t necessarily equal the maximum integer id

The maximum id of all the elements in this map

If this map contains the specified key

Retrieve the value associated with the specified key, or None if the value is not present

Keys that implement IntegerId are expected to be cheap, so we don’t borrow the key.

Retrieve a mutable reference to the value associated with the specified key, or None if the value is not present

Insert the specified value, associating it with a key

Returns the value previously associated with they key, or None if there wasn’t any

Remove the value associated with the specified key, or None if there isn’t any

Retrieve the entry associated with the specified key

Mimics the HashMap entry aPI

Iterate over all the keys and values in this map

Iterate over all the entries in this map, giving mutable references to the keys

Iterate over all the keys in the map

Iterate over all the values in the map

Iterate over mutable references to all the values in the map

Clear all the entries the map

Like Vec::clear this should retain the underlying memory for future use.

Retains only the elements specified by the predicate.

let mut map: IdMap<usize, usize> = (0..8).map(|x|(x, x*10)).collect();
map.retain(|k, _| k % 2 == 0);
assert_eq!(
    map.into_iter().collect::<Vec<_>>(),
    vec![(0, 0), (2, 20), (4, 40), (6, 60)]
);

Reserve space for the specified number of additional elements

Give a wrapper that will debug the underlying representation of this IdMap

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. 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

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

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

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable 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

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

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

Checks if two have the same contents, ignoring the order.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. 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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.