double_map/lib.rs
1//! Double map
2//!
3//! **`This crate is an attempt to provide Rust hash map with double key to single
4//! data/value.`**
5//!
6//! Sometimes during development, it may be necessary to have a data structure like
7//! a [`HashMaps`](`std::collections::HashMap`) but with two different keys referring
8//! to the same data.
9//! For example, if you have some data with a unique ID and a name, then you create
10//! a structure that contains the name, and store it in a normal HashMap using the
11//! unique ID as the key. However, finding the element throughout the name will be
12//! performed with `O(n)` time. The same is true for the reverse case.
13//!
14//! This crate try to resolve this contradiction by providing a [`DHashMap`] structure -
15//! a map where you can add, look up and remove elements using either the first
16//! key of type `K1` or the second key of type `K2`.
17//! Internally, it uses two [`HashMaps`](`std::collections::HashMap`): the first
18//! is of type `HashMap<K1, (K2, V)>` and the second is of type `HashMap<K2, K1>`.
19//! Using two `HashMap`'s insides instead one brings to the performance and
20//! memory penalty.
21//!
22//! It is recommended to use the first key of type `K1` for quick access to the data,
23//! because indexing by the second key of type `K2` requires two HashMap lookups.
24
25#![warn(rustdoc::broken_intra_doc_links)]
26#![warn(missing_docs)]
27
28mod map;
29
30pub mod dhash_map {
31 //! A hash map with double keys implemented as wrapper above two
32 //! [`HashMaps`](`std::collections::HashMap`).
33 pub use crate::map::*;
34}
35
36pub use crate::map::DHashMap;