Like a HashMap, but allows you to use two different keys to the same value/data.
Sometimes during development, it may be necessary to have a data structure like
a HashMap
but with two different keys referring to the same data.
For example, if you have some data with a unique ID and a name, then you create
a structure that contains the name, and store it in a normal HashMap
using
the unique ID as the key. However, finding the element throughout the name will be
performed with O(n) time. The same is true for the reverse case.
This crate tries to resolve this contradiction by providing a DHashMap structure -
a map where you can add, look up and remove elements using either the first key
of type K1
or the second key of type K2
.
Internally, it uses two maps: the first is of type HashMap<K1, (K2, V)>
and
the second is of type HashMap<K2, K1>
. Using two HashMap
's inside instead
one brings to the performance and memory penalty.
It is recommended to use the first key of type K1
of quick access to the data,
because indexing by the second key of type K2
requires two HashMap
lookups.
Double Map is in active development. The design goal is implementing the whole HashMap interface. Look at Change log for more information.
-
new
: Done sincev0.1.0
-
with_capacity
: Done sincev0.1.0
-
with_hasher
: Done sincev0.1.0
-
with_capacity_and_hasher
: Done sincev0.1.0
-
capacity
: Done sincev0.1.0
-
keys
: Done sincev0.6.0
-
into_keys
: Done sincev0.12.0
-
values
: Done sincev0.6.0
-
values_mut
: Done sincev0.6.0
-
into_values
: Done sincev0.12.0
-
iter
: Done sincev0.4.0
-
iter_mut
: Done sincev0.5.0
-
len
: Done sincev0.1.0
-
is_empty
: Done sincev0.1.0
-
drain
: Done sincev0.10.0
-
drain_filter
: Under development -
retain
: Under development -
clear
: Done sincev0.1.0
-
hasher
: Done sincev0.1.0
-
reserve
: Done sincev0.1.0
-
try_reserve
: Done sincev0.1.0
-
shrink_to_fit
: Done sincev0.1.0
-
shrink_to
: Done sincev0.1.0
-
entry
: Done sincev0.1.0
-
get
: Done sincev0.1.0
andv0.8.0
(get_key1
,get_key2
,get_keys
methods) -
get_key_value
: Done sincev0.8.0
(get_key1_value
,get_key2_value
,get_keys_value
methods) -
contains_key
: Done sincev0.7.0
(contains_key1
,contains_key2
andcontains_keys
methods) -
get_mut
: Done sincev0.1.0
(get_mut_key1
andget_mut_key2
methods) -
insert
: Done sincev0.1.0
(insert_unchecked
andinsert
methods) -
try_insert
: Done sincev0.1.0
-
remove
: Done sincev0.1.0
(remove_key1
andremove_key2
methods) -
remove_entry
: Under development -
raw_entry_mut
: Under development -
raw_entry
: Under development
-
Clone
: Done sincev0.1.0
-
Debug
: Done sincev0.9.0
-
Default
: Done sincev0.3.0
-
Extend
: Done sincev0.2.0
(some update in versionv0.12.0
) -
From
: Done sincev0.14.0
-
FromIterator
: Done sincev0.2.0
-
Index
: Done sincev0.14.0
-
IntoIterator
: Done sincev0.11.0
-
PartialEq
: Done sincev0.9.0
-
Eq
: Done sincev0.11.0
Licensed under Apache License, Version 2.0, (LICENSE or https://www.apache.org/licenses/LICENSE-2.0) at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.