ordermap/map/
raw_entry_v1.rs

1//! Opt-in access to the experimental raw entry API.
2//!
3//! This module is designed to mimic the raw entry API of [`HashMap`][std::collections::hash_map],
4//! matching its unstable state as of Rust 1.75. See the tracking issue
5//! [rust#56167](https://github.com/rust-lang/rust/issues/56167) for more details.
6//!
7//! The trait [`RawEntryApiV1`] and the `_v1` suffix on its methods are meant to insulate this for
8//! the future, in case later breaking changes are needed. If the standard library stabilizes its
9//! `hash_raw_entry` feature (or some replacement), matching *inherent* methods will be added to
10//! `OrderMap` without such an opt-in trait.
11
12use crate::{Equivalent, OrderMap};
13use core::fmt;
14use core::hash::{BuildHasher, Hash};
15use indexmap::map::raw_entry_v1 as ix;
16use indexmap::map::RawEntryApiV1 as _;
17
18#[cfg(doc)]
19use alloc::vec::Vec;
20
21/// Opt-in access to the experimental raw entry API.
22///
23/// See the [`raw_entry_v1`][self] module documentation for more information.
24pub trait RawEntryApiV1<K, V, S>: private::Sealed {
25    /// Creates a raw immutable entry builder for the [`OrderMap`].
26    ///
27    /// Raw entries provide the lowest level of control for searching and
28    /// manipulating a map. They must be manually initialized with a hash and
29    /// then manually searched.
30    ///
31    /// This is useful for
32    /// * Hash memoization
33    /// * Using a search key that doesn't work with the [`Equivalent`] trait
34    /// * Using custom comparison logic without newtype wrappers
35    ///
36    /// Unless you are in such a situation, higher-level and more foolproof APIs like
37    /// [`get`][OrderMap::get] should be preferred.
38    ///
39    /// Immutable raw entries have very limited use; you might instead want
40    /// [`raw_entry_mut_v1`][Self::raw_entry_mut_v1].
41    ///
42    /// # Examples
43    ///
44    /// ```
45    /// use core::hash::{BuildHasher, Hash};
46    /// use ordermap::map::{OrderMap, RawEntryApiV1};
47    ///
48    /// let mut map = OrderMap::new();
49    /// map.extend([("a", 100), ("b", 200), ("c", 300)]);
50    ///
51    /// fn compute_hash<K: Hash + ?Sized, S: BuildHasher>(hash_builder: &S, key: &K) -> u64 {
52    ///     use core::hash::Hasher;
53    ///     let mut state = hash_builder.build_hasher();
54    ///     key.hash(&mut state);
55    ///     state.finish()
56    /// }
57    ///
58    /// for k in ["a", "b", "c", "d", "e", "f"] {
59    ///     let hash = compute_hash(map.hasher(), k);
60    ///     let i = map.get_index_of(k);
61    ///     let v = map.get(k);
62    ///     let kv = map.get_key_value(k);
63    ///     let ikv = map.get_full(k);
64    ///
65    ///     println!("Key: {} and value: {:?}", k, v);
66    ///
67    ///     assert_eq!(map.raw_entry_v1().from_key(k), kv);
68    ///     assert_eq!(map.raw_entry_v1().from_hash(hash, |q| *q == k), kv);
69    ///     assert_eq!(map.raw_entry_v1().from_key_hashed_nocheck(hash, k), kv);
70    ///     assert_eq!(map.raw_entry_v1().from_hash_full(hash, |q| *q == k), ikv);
71    ///     assert_eq!(map.raw_entry_v1().index_from_hash(hash, |q| *q == k), i);
72    /// }
73    /// ```
74    fn raw_entry_v1(&self) -> RawEntryBuilder<'_, K, V, S>;
75
76    /// Creates a raw entry builder for the [`OrderMap`].
77    ///
78    /// Raw entries provide the lowest level of control for searching and
79    /// manipulating a map. They must be manually initialized with a hash and
80    /// then manually searched. After this, insertions into a vacant entry
81    /// still require an owned key to be provided.
82    ///
83    /// Raw entries are useful for such exotic situations as:
84    ///
85    /// * Hash memoization
86    /// * Deferring the creation of an owned key until it is known to be required
87    /// * Using a search key that doesn't work with the [`Equivalent`] trait
88    /// * Using custom comparison logic without newtype wrappers
89    ///
90    /// Because raw entries provide much more low-level control, it's much easier
91    /// to put the `OrderMap` into an inconsistent state which, while memory-safe,
92    /// will cause the map to produce seemingly random results. Higher-level and more
93    /// foolproof APIs like [`entry`][OrderMap::entry] should be preferred when possible.
94    ///
95    /// Raw entries give mutable access to the keys. This must not be used
96    /// to modify how the key would compare or hash, as the map will not re-evaluate
97    /// where the key should go, meaning the keys may become "lost" if their
98    /// location does not reflect their state. For instance, if you change a key
99    /// so that the map now contains keys which compare equal, search may start
100    /// acting erratically, with two keys randomly masking each other. Implementations
101    /// are free to assume this doesn't happen (within the limits of memory-safety).
102    ///
103    /// # Examples
104    ///
105    /// ```
106    /// use core::hash::{BuildHasher, Hash};
107    /// use ordermap::map::{OrderMap, RawEntryApiV1};
108    /// use ordermap::map::raw_entry_v1::RawEntryMut;
109    ///
110    /// let mut map = OrderMap::new();
111    /// map.extend([("a", 100), ("b", 200), ("c", 300)]);
112    ///
113    /// fn compute_hash<K: Hash + ?Sized, S: BuildHasher>(hash_builder: &S, key: &K) -> u64 {
114    ///     use core::hash::Hasher;
115    ///     let mut state = hash_builder.build_hasher();
116    ///     key.hash(&mut state);
117    ///     state.finish()
118    /// }
119    ///
120    /// // Existing key (insert and update)
121    /// match map.raw_entry_mut_v1().from_key("a") {
122    ///     RawEntryMut::Vacant(_) => unreachable!(),
123    ///     RawEntryMut::Occupied(mut view) => {
124    ///         assert_eq!(view.index(), 0);
125    ///         assert_eq!(view.get(), &100);
126    ///         let v = view.get_mut();
127    ///         let new_v = (*v) * 10;
128    ///         *v = new_v;
129    ///         assert_eq!(view.insert(1111), 1000);
130    ///     }
131    /// }
132    ///
133    /// assert_eq!(map["a"], 1111);
134    /// assert_eq!(map.len(), 3);
135    ///
136    /// // Existing key (take)
137    /// let hash = compute_hash(map.hasher(), "c");
138    /// match map.raw_entry_mut_v1().from_key_hashed_nocheck(hash, "c") {
139    ///     RawEntryMut::Vacant(_) => unreachable!(),
140    ///     RawEntryMut::Occupied(view) => {
141    ///         assert_eq!(view.index(), 2);
142    ///         assert_eq!(view.remove_entry(), ("c", 300));
143    ///     }
144    /// }
145    /// assert_eq!(map.raw_entry_v1().from_key("c"), None);
146    /// assert_eq!(map.len(), 2);
147    ///
148    /// // Nonexistent key (insert and update)
149    /// let key = "d";
150    /// let hash = compute_hash(map.hasher(), key);
151    /// match map.raw_entry_mut_v1().from_hash(hash, |q| *q == key) {
152    ///     RawEntryMut::Occupied(_) => unreachable!(),
153    ///     RawEntryMut::Vacant(view) => {
154    ///         assert_eq!(view.index(), 2);
155    ///         let (k, value) = view.insert("d", 4000);
156    ///         assert_eq!((*k, *value), ("d", 4000));
157    ///         *value = 40000;
158    ///     }
159    /// }
160    /// assert_eq!(map["d"], 40000);
161    /// assert_eq!(map.len(), 3);
162    ///
163    /// match map.raw_entry_mut_v1().from_hash(hash, |q| *q == key) {
164    ///     RawEntryMut::Vacant(_) => unreachable!(),
165    ///     RawEntryMut::Occupied(view) => {
166    ///         assert_eq!(view.index(), 2);
167    ///         assert_eq!(view.swap_remove_entry(), ("d", 40000));
168    ///     }
169    /// }
170    /// assert_eq!(map.get("d"), None);
171    /// assert_eq!(map.len(), 2);
172    /// ```
173    fn raw_entry_mut_v1(&mut self) -> RawEntryBuilderMut<'_, K, V, S>;
174}
175
176impl<K, V, S> RawEntryApiV1<K, V, S> for OrderMap<K, V, S> {
177    fn raw_entry_v1(&self) -> RawEntryBuilder<'_, K, V, S> {
178        RawEntryBuilder {
179            inner: self.inner.raw_entry_v1(),
180        }
181    }
182
183    fn raw_entry_mut_v1(&mut self) -> RawEntryBuilderMut<'_, K, V, S> {
184        RawEntryBuilderMut {
185            inner: self.inner.raw_entry_mut_v1(),
186        }
187    }
188}
189
190/// A builder for computing where in an [`OrderMap`] a key-value pair would be stored.
191///
192/// This `struct` is created by the [`OrderMap::raw_entry_v1`] method, provided by the
193/// [`RawEntryApiV1`] trait. See its documentation for more.
194pub struct RawEntryBuilder<'a, K, V, S> {
195    inner: ix::RawEntryBuilder<'a, K, V, S>,
196}
197
198impl<K, V, S> fmt::Debug for RawEntryBuilder<'_, K, V, S> {
199    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
200        f.debug_struct("RawEntryBuilder").finish_non_exhaustive()
201    }
202}
203
204impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
205    /// Access an entry by key.
206    pub fn from_key<Q>(self, key: &Q) -> Option<(&'a K, &'a V)>
207    where
208        S: BuildHasher,
209        Q: ?Sized + Hash + Equivalent<K>,
210    {
211        self.inner.from_key(key)
212    }
213
214    /// Access an entry by a key and its hash.
215    pub fn from_key_hashed_nocheck<Q>(self, hash: u64, key: &Q) -> Option<(&'a K, &'a V)>
216    where
217        Q: ?Sized + Equivalent<K>,
218    {
219        self.inner.from_key_hashed_nocheck(hash, key)
220    }
221
222    /// Access an entry by hash.
223    pub fn from_hash<F>(self, hash: u64, is_match: F) -> Option<(&'a K, &'a V)>
224    where
225        F: FnMut(&K) -> bool,
226    {
227        self.inner.from_hash(hash, is_match)
228    }
229
230    /// Access an entry by hash, including its index.
231    pub fn from_hash_full<F>(self, hash: u64, is_match: F) -> Option<(usize, &'a K, &'a V)>
232    where
233        F: FnMut(&K) -> bool,
234    {
235        self.inner.from_hash_full(hash, is_match)
236    }
237
238    /// Access the index of an entry by hash.
239    pub fn index_from_hash<F>(self, hash: u64, is_match: F) -> Option<usize>
240    where
241        F: FnMut(&K) -> bool,
242    {
243        self.inner.index_from_hash(hash, is_match)
244    }
245}
246
247/// A builder for computing where in an [`OrderMap`] a key-value pair would be stored.
248///
249/// This `struct` is created by the [`OrderMap::raw_entry_mut_v1`] method, provided by the
250/// [`RawEntryApiV1`] trait. See its documentation for more.
251pub struct RawEntryBuilderMut<'a, K, V, S> {
252    inner: ix::RawEntryBuilderMut<'a, K, V, S>,
253}
254
255impl<K, V, S> fmt::Debug for RawEntryBuilderMut<'_, K, V, S> {
256    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
257        f.debug_struct("RawEntryBuilderMut").finish_non_exhaustive()
258    }
259}
260
261impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
262    /// Access an entry by key.
263    pub fn from_key<Q>(self, key: &Q) -> RawEntryMut<'a, K, V, S>
264    where
265        S: BuildHasher,
266        Q: ?Sized + Hash + Equivalent<K>,
267    {
268        RawEntryMut::new(self.inner.from_key(key))
269    }
270
271    /// Access an entry by a key and its hash.
272    pub fn from_key_hashed_nocheck<Q>(self, hash: u64, key: &Q) -> RawEntryMut<'a, K, V, S>
273    where
274        Q: ?Sized + Equivalent<K>,
275    {
276        RawEntryMut::new(self.inner.from_key_hashed_nocheck(hash, key))
277    }
278
279    /// Access an entry by hash.
280    pub fn from_hash<F>(self, hash: u64, is_match: F) -> RawEntryMut<'a, K, V, S>
281    where
282        F: FnMut(&K) -> bool,
283    {
284        RawEntryMut::new(self.inner.from_hash(hash, is_match))
285    }
286}
287
288/// Raw entry for an existing key-value pair or a vacant location to
289/// insert one.
290pub enum RawEntryMut<'a, K, V, S> {
291    /// Existing slot with equivalent key.
292    Occupied(RawOccupiedEntryMut<'a, K, V, S>),
293    /// Vacant slot (no equivalent key in the map).
294    Vacant(RawVacantEntryMut<'a, K, V, S>),
295}
296
297impl<K: fmt::Debug, V: fmt::Debug, S> fmt::Debug for RawEntryMut<'_, K, V, S> {
298    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
299        let mut tuple = f.debug_tuple("RawEntryMut");
300        match self {
301            Self::Vacant(v) => tuple.field(v),
302            Self::Occupied(o) => tuple.field(o),
303        };
304        tuple.finish()
305    }
306}
307
308impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
309    fn new(entry: ix::RawEntryMut<'a, K, V, S>) -> Self {
310        match entry {
311            ix::RawEntryMut::Occupied(inner) => Self::Occupied(RawOccupiedEntryMut { inner }),
312            ix::RawEntryMut::Vacant(inner) => Self::Vacant(RawVacantEntryMut { inner }),
313        }
314    }
315
316    /// Return the index where the key-value pair exists or may be inserted.
317    #[inline]
318    pub fn index(&self) -> usize {
319        match self {
320            Self::Occupied(entry) => entry.index(),
321            Self::Vacant(entry) => entry.index(),
322        }
323    }
324
325    /// Inserts the given default key and value in the entry if it is vacant and returns mutable
326    /// references to them. Otherwise mutable references to an already existent pair are returned.
327    pub fn or_insert(self, default_key: K, default_value: V) -> (&'a mut K, &'a mut V)
328    where
329        K: Hash,
330        S: BuildHasher,
331    {
332        match self {
333            Self::Occupied(entry) => entry.into_key_value_mut(),
334            Self::Vacant(entry) => entry.insert(default_key, default_value),
335        }
336    }
337
338    /// Inserts the result of the `call` function in the entry if it is vacant and returns mutable
339    /// references to them. Otherwise mutable references to an already existent pair are returned.
340    pub fn or_insert_with<F>(self, call: F) -> (&'a mut K, &'a mut V)
341    where
342        F: FnOnce() -> (K, V),
343        K: Hash,
344        S: BuildHasher,
345    {
346        match self {
347            Self::Occupied(entry) => entry.into_key_value_mut(),
348            Self::Vacant(entry) => {
349                let (key, value) = call();
350                entry.insert(key, value)
351            }
352        }
353    }
354
355    /// Modifies the entry if it is occupied.
356    pub fn and_modify<F>(mut self, f: F) -> Self
357    where
358        F: FnOnce(&mut K, &mut V),
359    {
360        if let Self::Occupied(entry) = &mut self {
361            let (k, v) = entry.get_key_value_mut();
362            f(k, v);
363        }
364        self
365    }
366}
367
368/// A raw view into an occupied entry in an [`OrderMap`].
369/// It is part of the [`RawEntryMut`] enum.
370pub struct RawOccupiedEntryMut<'a, K, V, S> {
371    inner: ix::RawOccupiedEntryMut<'a, K, V, S>,
372}
373
374impl<K: fmt::Debug, V: fmt::Debug, S> fmt::Debug for RawOccupiedEntryMut<'_, K, V, S> {
375    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
376        f.debug_struct("RawOccupiedEntryMut")
377            .field("key", self.key())
378            .field("value", self.get())
379            .finish_non_exhaustive()
380    }
381}
382
383impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
384    /// Return the index of the key-value pair
385    #[inline]
386    pub fn index(&self) -> usize {
387        self.inner.index()
388    }
389
390    /// Gets a reference to the entry's key in the map.
391    ///
392    /// Note that this is not the key that was used to find the entry. There may be an observable
393    /// difference if the key type has any distinguishing features outside of `Hash` and `Eq`, like
394    /// extra fields or the memory address of an allocation.
395    pub fn key(&self) -> &K {
396        self.inner.key()
397    }
398
399    /// Gets a mutable reference to the entry's key in the map.
400    ///
401    /// Note that this is not the key that was used to find the entry. There may be an observable
402    /// difference if the key type has any distinguishing features outside of `Hash` and `Eq`, like
403    /// extra fields or the memory address of an allocation.
404    pub fn key_mut(&mut self) -> &mut K {
405        self.inner.key_mut()
406    }
407
408    /// Converts into a mutable reference to the entry's key in the map,
409    /// with a lifetime bound to the map itself.
410    ///
411    /// Note that this is not the key that was used to find the entry. There may be an observable
412    /// difference if the key type has any distinguishing features outside of `Hash` and `Eq`, like
413    /// extra fields or the memory address of an allocation.
414    pub fn into_key(self) -> &'a mut K {
415        self.inner.into_key()
416    }
417
418    /// Gets a reference to the entry's value in the map.
419    pub fn get(&self) -> &V {
420        self.inner.get()
421    }
422
423    /// Gets a mutable reference to the entry's value in the map.
424    ///
425    /// If you need a reference which may outlive the destruction of the
426    /// [`RawEntryMut`] value, see [`into_mut`][Self::into_mut].
427    pub fn get_mut(&mut self) -> &mut V {
428        self.inner.get_mut()
429    }
430
431    /// Converts into a mutable reference to the entry's value in the map,
432    /// with a lifetime bound to the map itself.
433    pub fn into_mut(self) -> &'a mut V {
434        self.inner.into_mut()
435    }
436
437    /// Gets a reference to the entry's key and value in the map.
438    pub fn get_key_value(&self) -> (&K, &V) {
439        self.inner.get_key_value()
440    }
441
442    /// Gets a reference to the entry's key and value in the map.
443    pub fn get_key_value_mut(&mut self) -> (&mut K, &mut V) {
444        self.inner.get_key_value_mut()
445    }
446
447    /// Converts into a mutable reference to the entry's key and value in the map,
448    /// with a lifetime bound to the map itself.
449    pub fn into_key_value_mut(self) -> (&'a mut K, &'a mut V) {
450        self.inner.into_key_value_mut()
451    }
452
453    /// Sets the value of the entry, and returns the entry's old value.
454    pub fn insert(&mut self, value: V) -> V {
455        self.inner.insert(value)
456    }
457
458    /// Sets the key of the entry, and returns the entry's old key.
459    pub fn insert_key(&mut self, key: K) -> K {
460        self.inner.insert_key(key)
461    }
462
463    /// Remove the key, value pair stored in the map for this entry, and return the value.
464    ///
465    /// **NOTE:** This is equivalent to indexmap's
466    /// [`RawOccupiedEntryMut::shift_remove`][ix::RawOccupiedEntryMut::shift_remove], and
467    /// like [`Vec::remove`], the pair is removed by shifting all of the
468    /// elements that follow it, preserving their relative order.
469    /// **This perturbs the index of all of those elements!**
470    ///
471    /// Computes in **O(n)** time (average).
472    pub fn remove(self) -> V {
473        self.inner.shift_remove()
474    }
475
476    /// Remove the key, value pair stored in the map for this entry, and return the value.
477    ///
478    /// Like [`Vec::swap_remove`], the pair is removed by swapping it with
479    /// the last element of the map and popping it off.
480    /// **This perturbs the position of what used to be the last element!**
481    ///
482    /// Computes in **O(1)** time (average).
483    pub fn swap_remove(self) -> V {
484        self.inner.swap_remove()
485    }
486
487    /// Remove and return the key, value pair stored in the map for this entry
488    ///
489    /// **NOTE:** This is equivalent to indexmap's
490    /// [`RawOccupiedEntryMut::shift_remove_entry`][ix::RawOccupiedEntryMut::shift_remove_entry], and
491    /// like [`Vec::remove`], the pair is removed by shifting all of the
492    /// elements that follow it, preserving their relative order.
493    /// **This perturbs the index of all of those elements!**
494    ///
495    /// Computes in **O(n)** time (average).
496    pub fn remove_entry(self) -> (K, V) {
497        self.inner.shift_remove_entry()
498    }
499
500    /// Remove and return the key, value pair stored in the map for this entry
501    ///
502    /// Like [`Vec::swap_remove`], the pair is removed by swapping it with
503    /// the last element of the map and popping it off.
504    /// **This perturbs the position of what used to be the last element!**
505    ///
506    /// Computes in **O(1)** time (average).
507    pub fn swap_remove_entry(self) -> (K, V) {
508        self.inner.swap_remove_entry()
509    }
510
511    /// Moves the position of the entry to a new index
512    /// by shifting all other entries in-between.
513    ///
514    /// This is equivalent to [`OrderMap::move_index`]
515    /// coming `from` the current [`.index()`][Self::index].
516    ///
517    /// * If `self.index() < to`, the other pairs will shift down while the targeted pair moves up.
518    /// * If `self.index() > to`, the other pairs will shift up while the targeted pair moves down.
519    ///
520    /// ***Panics*** if `to` is out of bounds.
521    ///
522    /// Computes in **O(n)** time (average).
523    #[track_caller]
524    pub fn move_index(self, to: usize) {
525        self.inner.move_index(to);
526    }
527
528    /// Swaps the position of entry with another.
529    ///
530    /// This is equivalent to [`OrderMap::swap_indices`]
531    /// with the current [`.index()`][Self::index] as one of the two being swapped.
532    ///
533    /// ***Panics*** if the `other` index is out of bounds.
534    ///
535    /// Computes in **O(1)** time (average).
536    #[track_caller]
537    pub fn swap_indices(self, other: usize) {
538        self.inner.swap_indices(other);
539    }
540}
541
542/// A view into a vacant raw entry in an [`OrderMap`].
543/// It is part of the [`RawEntryMut`] enum.
544pub struct RawVacantEntryMut<'a, K, V, S> {
545    inner: ix::RawVacantEntryMut<'a, K, V, S>,
546}
547
548impl<K, V, S> fmt::Debug for RawVacantEntryMut<'_, K, V, S> {
549    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
550        f.debug_struct("RawVacantEntryMut").finish_non_exhaustive()
551    }
552}
553
554impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
555    /// Return the index where a key-value pair may be inserted.
556    pub fn index(&self) -> usize {
557        self.inner.index()
558    }
559
560    /// Inserts the given key and value into the map,
561    /// and returns mutable references to them.
562    pub fn insert(self, key: K, value: V) -> (&'a mut K, &'a mut V)
563    where
564        K: Hash,
565        S: BuildHasher,
566    {
567        self.inner.insert(key, value)
568    }
569
570    /// Inserts the given key and value into the map with the provided hash,
571    /// and returns mutable references to them.
572    pub fn insert_hashed_nocheck(self, hash: u64, key: K, value: V) -> (&'a mut K, &'a mut V) {
573        self.inner.insert_hashed_nocheck(hash, key, value)
574    }
575
576    /// Inserts the given key and value into the map at the given index,
577    /// shifting others to the right, and returns mutable references to them.
578    ///
579    /// ***Panics*** if `index` is out of bounds.
580    ///
581    /// Computes in **O(n)** time (average).
582    #[track_caller]
583    pub fn shift_insert(self, index: usize, key: K, value: V) -> (&'a mut K, &'a mut V)
584    where
585        K: Hash,
586        S: BuildHasher,
587    {
588        self.inner.shift_insert(index, key, value)
589    }
590
591    /// Inserts the given key and value into the map with the provided hash
592    /// at the given index, and returns mutable references to them.
593    ///
594    /// ***Panics*** if `index` is out of bounds.
595    ///
596    /// Computes in **O(n)** time (average).
597    #[track_caller]
598    pub fn shift_insert_hashed_nocheck(
599        self,
600        index: usize,
601        hash: u64,
602        key: K,
603        value: V,
604    ) -> (&'a mut K, &'a mut V) {
605        self.inner
606            .shift_insert_hashed_nocheck(index, hash, key, value)
607    }
608}
609
610mod private {
611    pub trait Sealed {}
612
613    impl<K, V, S> Sealed for super::OrderMap<K, V, S> {}
614}