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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use core::borrow::Borrow;
use core::hash::{Hash, BuildHasher};

#[cfg(feature = "use_std")] use std::collections::hash_map::HashMap;
#[cfg(not(feature = "use_std"))] use hashmap_core::HashMap;

use super::super::*;


impl<K, V, S> Collection for HashMap<K, V, S>
    where K: Eq + Hash,
          S: BuildHasher,
{
    #[inline(always)]
    fn len(&self) -> usize {
        HashMap::<K, V, S>::len(self)
    }
}

impl<K, V, S> CollectionMut for HashMap<K, V, S>
    where K: Eq + Hash,
          S: BuildHasher,
{
    #[inline(always)]
    fn clear(&mut self) {
        HashMap::<K, V, S>::drain(self);
    }
}

impl<K, V, S> Create<(K, V)> for HashMap<K, V, S>
    where K: Eq + Hash,
          S: Default + BuildHasher,
{

    #[inline(always)]
    fn create() -> Self { HashMap::<K, V, S>::default() }
    #[inline(always)]
    fn create_with_capacity(_: usize) -> Self { HashMap::<K, V, S>::default() }

    #[inline(always)]
    fn add_element(mut self, (key, value): (K, V)) -> Self {
        HashMap::<K, V, S>::insert(&mut self, key, value);
        self
    }
}

impl<'a, K, V, S> Insert<K, V> for HashMap<K, V, S>
    where K: Eq + Hash,
          S: BuildHasher
{
    type Output = Option<V>;

    #[inline]
    fn insert(&mut self, k: K, v: V) -> Self::Output {
        HashMap::<K, V, S>::insert(self, k, v)
    }
}

impl<'a, K, Q: ?Sized, V, S> Remove<&'a Q> for HashMap<K, V, S>
    where K: Eq + Hash + Borrow<Q>,
          Q: Eq + Hash,
          S: BuildHasher
{
    type Output = Option<V>;

    #[inline]
    fn remove(&mut self, q: &Q) -> Self::Output {
        HashMap::<K, V, S>::remove(self, q)
    }
}

impl<'a, K, Q: ?Sized, V, S> Get<&'a Q> for HashMap<K, V, S>
    where K: Eq + Hash + Borrow<Q>,
          Q: Eq + Hash,
          S: BuildHasher,
{
    type Output = V;

    #[inline(always)]
    fn get(&self, q: &Q) -> Option<&Self::Output> {
        HashMap::<K, V, S>::get(self, q)
    }
}
impl<'a, K, Q: ?Sized, V, S> GetMut<&'a Q> for HashMap<K, V, S>
    where K: Eq + Hash + Borrow<Q>,
          Q: Eq + Hash,
          S: BuildHasher,
{
    #[inline(always)]
    fn get_mut(&mut self, q: &Q) -> Option<&mut Self::Output> {
        HashMap::<K, V, S>::get_mut(self, q)
    }
}