1 pub use rustc_hash
::FxHashMap
;
2 use std
::borrow
::Borrow
;
3 use std
::collections
::hash_map
::Entry
;
7 /// A deterministic wrapper around FxHashMap that does not provide iteration support.
9 /// It supports insert, remove, get and get_mut functions from FxHashMap.
10 /// It also allows to convert hashmap to a sorted vector with the method `into_sorted_vector()`.
12 pub struct StableMap
<K
, V
> {
13 base
: FxHashMap
<K
, V
>,
16 impl<K
, V
> Default
for StableMap
<K
, V
>
20 fn default() -> StableMap
<K
, V
> {
25 impl<K
, V
> fmt
::Debug
for StableMap
<K
, V
>
27 K
: Eq
+ Hash
+ fmt
::Debug
,
30 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
31 write
!(f
, "{:?}", self.base
)
35 impl<K
, V
> PartialEq
for StableMap
<K
, V
>
40 fn eq(&self, other
: &StableMap
<K
, V
>) -> bool
{
41 self.base
== other
.base
45 impl<K
, V
> Eq
for StableMap
<K
, V
>
52 impl<K
, V
> StableMap
<K
, V
>
56 pub fn new() -> StableMap
<K
, V
> {
57 StableMap { base: FxHashMap::default() }
60 pub fn into_sorted_vector(self) -> Vec
<(K
, V
)>
64 let mut vector
= self.base
.into_iter().collect
::<Vec
<_
>>();
65 vector
.sort_unstable_by_key(|pair
| pair
.0);
69 pub fn entry(&mut self, k
: K
) -> Entry
<'_
, K
, V
> {
73 pub fn get
<Q
: ?Sized
>(&self, k
: &Q
) -> Option
<&V
>
81 pub fn get_mut
<Q
: ?Sized
>(&mut self, k
: &Q
) -> Option
<&mut V
>
89 pub fn insert(&mut self, k
: K
, v
: V
) -> Option
<V
> {
90 self.base
.insert(k
, v
)
93 pub fn remove
<Q
: ?Sized
>(&mut self, k
: &Q
) -> Option
<V
>