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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use crate::internal::{
    entry::Entry,
    get_entry::{GetEntryByKey, GetEntryFromKey},
    occupied_entry::*,
    vacant_entry::*,
};

use core::hash::Hash;
use core::{borrow::Borrow, marker::PhantomData};

/// stand in for std::collections::HashMap
pub struct DummyHashMap<K, V> {
    phantom: PhantomData<(K, V)>,
}

/// Occupied entry of a HashMap.
///
/// This entry can be used to read the key, mutate the value,
/// or remove the key/value pair from the HashMap, without re-hashing.
pub struct DummyHashMapOccupiedEntry<'c, K, V> {
    _map: &'c mut DummyHashMap<K, V>,
}

/// Vacant entry of a HashMap.
///
/// This contains the key used to search for this entry,
/// and can read that key, or insert into the HashMap at that key,
/// when provided a value.
pub struct DummyHashMapVacantEntry<'c, K, V> {
    _map: &'c mut DummyHashMap<K, V>,
}

/// Raw vacant entry of a HashMap.
///
/// This is acquired from the `get_raw_entry` method, and can insert into
/// the HashMap when provided a `(K, V)` tuple where K hashes to the hash used
/// to aquire this entry. Inserting with a (K, V) tuple gives a `DummyHashMapOccupiedEntry`
pub struct DummyHashMapRawVacantEntry<'c, K, V> {
    _map: &'c mut DummyHashMap<K, V>,
}

/// An entry of a HashMap. This is either `DummyHashMapOccupiedEntry` or `DummyHashMapVacantEntry`.
pub type DummyHashMapEntry<'c, K, V> =
    Entry<DummyHashMapOccupiedEntry<'c, K, V>, DummyHashMapVacantEntry<'c, K, V>>;

/// A raw entry of a HashMap. This is either `DummyHashMapOccupiedEntry` or `DummyHashMapRawVacantEntry`.
pub type DummyHashMapRawEntry<'c, K, V> =
    Entry<DummyHashMapOccupiedEntry<'c, K, V>, DummyHashMapRawVacantEntry<'c, K, V>>;

impl<K, V> GetEntryFromKey<K, V> for DummyHashMap<K, V>
where
    K: Eq + Hash,
{
    type Occupied<'c> = DummyHashMapOccupiedEntry<'c, K, V>
    where
        Self: 'c;

    type Vacant<'c> = DummyHashMapVacantEntry<'c, K, V>
    where
        Self: 'c;

    fn get_entry_with_key<'c>(
        &'c mut self,
        key: K,
    ) -> crate::internal::entry::EntryWithSearchKey<Self::Occupied<'c>, Self::Vacant<'c>, K> {
        todo!()
    }
}

impl<K, V, Q> GetEntryByKey<K, V, Q> for DummyHashMap<K, V>
where
    K: Borrow<Q> + Clone + Eq + Hash,
    Q: Eq,
{
    fn get_entry<'c>(&'c mut self, key: &Q) -> Entry<Self::Occupied<'c>, Self::Vacant<'c>> {
        todo!()
    }

    fn vacate<'c>(&'c mut self, key: &Q) -> (Self::Vacant<'c>, Option<V>) {
        todo!()
    }
}

impl<'c, K, V> OccupiedEntry<'c> for DummyHashMapOccupiedEntry<'c, K, V> {
    type Value = V;

    fn get_value<'e>(&'e self) -> &'e Self::Value
    where
        'c: 'e,
    {
        todo!()
    }

    fn get_value_mut<'e>(&'e mut self) -> &mut Self::Value
    where
        'c: 'e,
    {
        todo!()
    }

    fn into_value_mut<'e>(self) -> &'c mut Self::Value {
        todo!()
    }
}

impl<'c, K, V> KeyedOccupiedEntry<'c> for DummyHashMapOccupiedEntry<'c, K, V> {
    type Key = K;

    type BorrowedKey = &'c K;

    fn get_pair<'e>(&'e self) -> (&'e Self::Key, &'e Self::Value)
    where
        'c: 'e,
    {
        todo!()
    }

    fn get_pair_mut<'e>(&'e mut self) -> (&'e Self::Key, &'e mut Self::Value)
    where
        'c: 'e,
    {
        todo!()
    }

    fn into_pair(self) -> (Self::BorrowedKey, &'c mut Self::Value) {
        todo!()
    }
}

impl<'c, K, V> RemovableOccupiedEntry<'c> for DummyHashMapOccupiedEntry<'c, K, V> {
    type Removed = DummyHashMapVacantEntry<'c, K, V>;

    fn remove(self) -> (V, Self::Removed) {
        todo!()
    }
}

impl<'c, K, V> EntryRemovableOccupiedEntry<'c> for DummyHashMapOccupiedEntry<'c, K, V> {
    type Vacant = DummyHashMapVacantEntry<'c, K, V>;

    fn recover_removed_entry(removed: Self::Removed) -> DummyHashMapEntry<'c, K, V> {
        Entry::Vacant(removed)
    }
}

impl<'c, K, V> VacantEntry<'c> for DummyHashMapVacantEntry<'c, K, V> {
    type Occupied = DummyHashMapOccupiedEntry<'c, K, V>;

    type Value = V;

    fn occupy(self, val: Self::Value) -> Self::Occupied {
        todo!()
    }
}

impl<'c, K, V> KeyedVacantEntry<'c> for DummyHashMapVacantEntry<'c, K, V> {
    type Key = K;

    fn get_key<'e>(&'e self) -> &'e Self::Key
    where
        'c: 'e,
    {
        todo!()
    }

    fn into_key(self) -> Self::Key {
        todo!()
    }
}

impl<'c, K, V> VacantEntry<'c> for DummyHashMapRawVacantEntry<'c, K, V> {
    type Occupied = DummyHashMapOccupiedEntry<'c, K, V>;

    type Value = (K, V);

    fn occupy(self, val: Self::Value) -> Self::Occupied {
        todo!()
    }
}

impl<'c, K, V> DummyHashMapRawVacantEntry<'c, K, V> {
    /// elevate a raw vacant entry to a regular vacant entry by providing a key.
    fn occupy_key(self, key: K) -> DummyHashMapVacantEntry<'c, K, V> {
        todo!()
    }
}

impl<K, V> DummyHashMap<K, V> {
    /// get a raw entry for a given hash.
    fn get_raw_entry(&mut self, hash: u64) -> DummyHashMapRawEntry<'_, K, V> {
        todo!()
    }
}