-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbi_hash_map.rs
37 lines (34 loc) · 859 Bytes
/
bi_hash_map.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::{
collections::HashMap,
fmt::Debug,
};
/// Bi-directional hashmap used to store the mapping between the internal
/// unstable indexes - generated by `IndexMap` and `IndexSet` - and the exposed
/// stable indexes.
pub(crate) struct BiHashMap<Index>
where
Index: Copy + Debug + Eq,
{
pub(crate) left: HashMap<usize, Index>,
pub(crate) right: HashMap<Index, usize>,
}
impl<Index> BiHashMap<Index>
where
Index: Copy + Debug + Eq,
{
/// Creates a new `BiHashMap` with no allocation.
pub(crate) fn new() -> BiHashMap<Index> {
Self {
left: HashMap::<usize, Index>::with_capacity(0),
right: HashMap::<Index, usize>::with_capacity(0),
}
}
}
impl<Index> Default for BiHashMap<Index>
where
Index: Copy + Debug + Eq,
{
fn default() -> Self {
BiHashMap::new()
}
}