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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
use crate::{
    get_entry::{GetFirstEntry, GetLastEntry},
    internal::{
        entry::Entry,
        get_entry::{GetEntryByKey, GetEntryFromKey},
        occupied_entry::*,
        vacant_entry::*,
    },
};

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

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

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

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

/// Raw vacant entry of a BTreeMap.
///
/// This is acquired from the `get_raw_entry` method, and can insert into
/// the BTreeMap when provided a `(K, V)` tuple where K sorts the same as the query used
/// to aquire this entry. Inserting with a (K, V) tuple gives a `DummyBTreeMapOccupiedEntry`
pub struct DummyBTreeMapRawVacantEntry<'c, K, V> {
    _map: &'c mut DummyBTreeMap<K, V>,
}

/// An entry of a BTreeMap. This is either `DummyBTreeMapOccupiedEntry` or `DummyBTreeMapVacantEntry`.
pub type DummyBTreeMapEntry<'c, K, V> =
    Entry<DummyBTreeMapOccupiedEntry<'c, K, V>, DummyBTreeMapVacantEntry<'c, K, V>>;

/// A raw entry of a BTreeMap. This is either `DummyBTreeMapOccupiedEntry` or `DummyBTreeMapRawVacantEntry`.
pub type DummyBTreeMapRawEntry<'c, K, V> =
    Entry<DummyBTreeMapOccupiedEntry<'c, K, V>, DummyBTreeMapRawVacantEntry<'c, K, V>>;

impl<K, V> GetEntryFromKey<K, V> for DummyBTreeMap<K, V>
where
    K: Ord,
{
    type Occupied<'c> = DummyBTreeMapOccupiedEntry<'c, K, V>
    where
        Self: 'c;

    type Vacant<'c> = DummyBTreeMapVacantEntry<'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 DummyBTreeMap<K, V>
where
    K: Borrow<Q> + Clone + Ord,
    Q: Ord,
{
    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<K, V> GetFirstEntry<V> for DummyBTreeMap<K, V>
where
    K: Ord,
{
    type Occupied<'c> = DummyBTreeMapOccupiedEntry<'c, K, V>
    where
        Self: 'c;

    fn get_first_occupied<'c>(&'c mut self) -> Option<Self::Occupied<'c>> {
        todo!()
    }
}

impl<K, V> GetLastEntry<V> for DummyBTreeMap<K, V>
where
    K: Ord,
{
    type Occupied<'c> = DummyBTreeMapOccupiedEntry<'c, K, V>
    where
        Self: 'c;

    fn get_last_occupied<'c>(&'c mut self) -> Option<Self::Occupied<'c>> {
        todo!()
    }
}

impl<'c, K, V> OccupiedEntry<'c> for DummyBTreeMapOccupiedEntry<'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 DummyBTreeMapOccupiedEntry<'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 DummyBTreeMapOccupiedEntry<'c, K, V> {
    type Removed = DummyBTreeMapVacantEntry<'c, K, V>;

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

impl<'c, K, V> EntryRemovableOccupiedEntry<'c> for DummyBTreeMapOccupiedEntry<'c, K, V> {
    type Vacant = DummyBTreeMapVacantEntry<'c, K, V>;

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

impl<'c, K, V> NextOccupiedFromOccupied<'c> for DummyBTreeMapOccupiedEntry<'c, K, V>
where
    K: Ord,
{
    fn get_next_occupied(mut self) -> Option<Self> {
        todo!()
    }
}

impl<'c, K, V> PrevOccupiedFromOccupied<'c> for DummyBTreeMapOccupiedEntry<'c, K, V>
where
    K: Ord,
{
    fn get_prev_occupied(mut self) -> Option<Self> {
        todo!()
    }
}

impl<'c, K, V> VacantEntry<'c> for DummyBTreeMapVacantEntry<'c, K, V> {
    type Occupied = DummyBTreeMapOccupiedEntry<'c, K, V>;

    type Value = V;

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

impl<'c, K, V> KeyedVacantEntry<'c> for DummyBTreeMapVacantEntry<'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> NextOccupiedFromVacant<'c> for DummyBTreeMapVacantEntry<'c, K, V>
where
    K: Ord,
{
    fn get_next_occupied(mut self) -> Option<Self::Occupied> {
        todo!()
    }
}

impl<'c, K, V> PrevOccupiedFromVacant<'c> for DummyBTreeMapVacantEntry<'c, K, V>
where
    K: Ord,
{
    fn get_prev_occupied(mut self) -> Option<Self::Occupied> {
        todo!()
    }
}

impl<'c, K, V> VacantEntry<'c> for DummyBTreeMapRawVacantEntry<'c, K, V> {
    type Occupied = DummyBTreeMapOccupiedEntry<'c, K, V>;

    type Value = (K, V);

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

impl<'c, K, V> NextOccupiedFromVacant<'c> for DummyBTreeMapRawVacantEntry<'c, K, V>
where
    K: Ord,
{
    fn get_next_occupied(mut self) -> Option<Self::Occupied> {
        todo!()
    }
}

impl<'c, K, V> PrevOccupiedFromVacant<'c> for DummyBTreeMapRawVacantEntry<'c, K, V>
where
    K: Ord,
{
    fn get_prev_occupied(mut self) -> Option<Self::Occupied> {
        todo!()
    }
}

impl<'c, K, V> DummyBTreeMapRawVacantEntry<'c, K, V> {
    /// Elevate a raw vacant entry to a regular vacant entry by providing a key.
    ///
    /// This key must evaluate to `Ordering::Equal` when passed to the comparator and query
    /// to maintain BTreeMap invariants.
    fn occupy_key(self, key: K) -> DummyBTreeMapVacantEntry<'c, K, V> {
        todo!()
    }
}

impl<K, V> DummyBTreeMap<K, V> {
    /// get a raw entry for a given query value and comparator.
    ///
    /// comparator must observe the transitive property for K and Q.
    /// (k1 < q) && (q < k2) => (k1 < k2).
    ///
    /// when inserting into this entry, `comparator(&inserted_key, &query)` must evaluate to `Ordering::Equal`.
    fn get_raw_entry<Q, Cmp>(
        &mut self,
        query: Q,
        comparator: Cmp,
    ) -> DummyBTreeMapRawEntry<'_, K, V>
    where
        Cmp: Fn(&K, &Q) -> std::cmp::Ordering,
    {
        todo!()
    }
}