Skip to main content

wt_indexset/concurrent/
map.rs

1use std::fmt::Debug;
2use std::sync::Arc;
3use std::{borrow::Borrow, iter::FusedIterator, ops::RangeBounds};
4
5use parking_lot::Mutex;
6
7use super::set::BTreeSet;
8use crate::core::node::NodeLike;
9use crate::{cdc::change::ChangeEvent, core::pair::Pair};
10
11#[derive(Debug)]
12pub struct BTreeMap<K, V, Node = Vec<Pair<K, V>>>
13where
14    K: Send + Ord + Clone + 'static,
15    V: Send + Clone + 'static,
16    Node: NodeLike<Pair<K, V>>,
17{
18    pub(crate) set: BTreeSet<Pair<K, V>, Node>,
19}
20
21impl<K, V, Node> Default for BTreeMap<K, V, Node>
22where
23    K: Send + Ord + Clone,
24    V: Send + Clone + 'static,
25    Node: NodeLike<Pair<K, V>> + Send + 'static,
26{
27    fn default() -> Self {
28        Self {
29            set: Default::default(),
30        }
31    }
32}
33
34pub struct Iter<'a, K, V, Node>
35where
36    K: Debug + Send + Ord + Clone + 'static,
37    V: Debug + Send + Clone + 'static,
38    Node: NodeLike<Pair<K, V>> + Send + 'static,
39{
40    inner: super::set::Iter<'a, Pair<K, V>, Node>,
41}
42
43impl<'a, K, V, Node> Iterator for Iter<'a, K, V, Node>
44where
45    K: Debug + Send + Ord + Clone + 'static,
46    V: Debug + Send + Clone + 'static,
47    Node: NodeLike<Pair<K, V>> + Send + 'static,
48{
49    type Item = (&'a K, &'a V);
50
51    fn next(&mut self) -> Option<Self::Item> {
52        if let Some(entry) = self.inner.next() {
53            return Some((&entry.key, &entry.value));
54        }
55
56        None
57    }
58}
59
60impl<'a, K, V, Node> DoubleEndedIterator for Iter<'a, K, V, Node>
61where
62    K: Debug + Send + Ord + Clone + 'static,
63    V: Debug + Send + Clone + 'static,
64    Node: NodeLike<Pair<K, V>> + Send + 'static,
65{
66    fn next_back(&mut self) -> Option<Self::Item> {
67        if let Some(entry) = self.inner.next_back() {
68            return Some((&entry.key, &entry.value));
69        }
70
71        None
72    }
73}
74
75impl<'a, K, V, Node> FusedIterator for Iter<'a, K, V, Node>
76where
77    K: Debug + Send + Ord + Clone + 'static,
78    V: Debug + Send + Clone + 'static,
79    Node: NodeLike<Pair<K, V>> + Send + 'static,
80{
81}
82
83pub struct Range<'a, K, V, Node>
84where
85    K: Debug + Send + Ord + Clone + 'static,
86    V: Debug + Send + Clone + 'static,
87    Node: NodeLike<Pair<K, V>> + Send + 'static,
88{
89    inner: super::set::Range<'a, Pair<K, V>, Node>,
90}
91
92impl<'a, K, V, Node> Iterator for Range<'a, K, V, Node>
93where
94    K: Debug + Send + Ord + Clone + 'static,
95    V: Debug + Send + Clone + 'static,
96    Node: NodeLike<Pair<K, V>> + Send + 'static,
97{
98    type Item = (&'a K, &'a V);
99
100    fn next(&mut self) -> Option<Self::Item> {
101        if let Some(entry) = self.inner.next() {
102            return Some((&entry.key, &entry.value));
103        }
104
105        None
106    }
107}
108
109impl<'a, K, V, Node> DoubleEndedIterator for Range<'a, K, V, Node>
110where
111    K: Debug + Send + Ord + Clone + 'static,
112    V: Debug + Send + Clone + 'static,
113    Node: NodeLike<Pair<K, V>> + Send + 'static,
114{
115    fn next_back(&mut self) -> Option<Self::Item> {
116        if let Some(entry) = self.inner.next_back() {
117            return Some((&entry.key, &entry.value));
118        }
119
120        None
121    }
122}
123
124impl<'a, K, V, Node> FusedIterator for Range<'a, K, V, Node>
125where
126    K: Debug + Send + Ord + Clone + 'static,
127    V: Debug + Send + Clone + 'static,
128    Node: NodeLike<Pair<K, V>> + Send + 'static,
129{
130}
131
132impl<K, V, Node> BTreeMap<K, V, Node>
133where
134    K: Debug + Send + Ord + Clone + 'static,
135    V: Debug + Send + Clone + 'static,
136    Node: NodeLike<Pair<K, V>> + Send + 'static,
137{
138    /// Makes a new, empty, persistent `BTreeMap`.
139    ///
140    /// # Examples
141    ///
142    /// Basic usage:
143    ///
144    /// ```
145    /// use wt_indexset::concurrent::map::BTreeMap;
146    ///
147    /// let mut map = BTreeMap::<usize, &str>::new();
148    ///
149    /// // entries can now be inserted into the empty map
150    /// map.insert(1, "a");
151    /// ```
152    pub fn new() -> Self {
153        Self {
154            set: Default::default(),
155        }
156    }
157    /// Makes a new, empty `BTreeMap` with the given maximum node size. Allocates one vec with
158    /// the capacity set to be the specified node size.
159    ///
160    /// # Examples
161    ///
162    /// ```
163    /// use wt_indexset::concurrent::map::BTreeMap;
164    ///
165    /// let map = BTreeMap::<i32, i32>::with_maximum_node_size(128);
166    pub fn with_maximum_node_size(node_capacity: usize) -> Self {
167        Self {
168            set: BTreeSet::with_maximum_node_size(node_capacity),
169        }
170    }
171    /// Adds full [`Node`] to this set. [`Node`] should be correct node with
172    /// values sorted.
173    #[cfg(feature = "cdc")]
174    pub fn attach_node(&self, node: Node) {
175        self.set.attach_node(node)
176    }
177    /// Returns iterator over this set's [`Node`]'s.
178    #[cfg(feature = "cdc")]
179    pub fn iter_nodes(&self) -> impl Iterator<Item = Arc<Mutex<Node>>> + '_ {
180        self.set.index.iter().map(|e| e.value().clone())
181    }
182    /// Returns `true` if the map contains a value for the specified key.
183    ///
184    /// The key may be any borrowed form of the map's key type, but the ordering
185    /// on the borrowed form *must* match the ordering on the key type.
186    ///
187    /// # Examples
188    ///
189    /// Basic usage:
190    ///
191    /// ```
192    /// use wt_indexset::concurrent::map::BTreeMap;
193    ///
194    /// let mut map = BTreeMap::<usize, &str>::new();
195    /// map.insert(1, "a");
196    /// assert_eq!(map.contains_key(&1), true);
197    /// assert_eq!(map.contains_key(&2), false);
198    /// ```
199    pub fn contains_key<Q>(&self, key: &Q) -> bool
200    where
201        Pair<K, V>: Borrow<Q> + Ord,
202        Q: Ord + ?Sized,
203    {
204        self.set.contains(key)
205    }
206    /// Returns a reference to a pair whose key corresponds to the input.
207    ///
208    /// The key may be any borrowed form of the map's key type, but the ordering
209    /// on the borrowed form *must* match the ordering on the key type.
210    ///
211    /// # Examples
212    ///
213    /// Basic usage:
214    ///
215    /// ```
216    /// use wt_indexset::concurrent::map::BTreeMap;
217    ///
218    /// let mut map = BTreeMap::<usize, &str>::new();
219    /// map.insert(1, "a");
220    /// assert_eq!(map.get(&1).and_then(|e| Some(e.get().value)), Some("a"));
221    /// assert_eq!(map.get(&2).and_then(|e| Some(e.get().value)), None);
222    /// ```
223    pub fn get<Q>(&self, key: &Q) -> Option<super::r#ref::Ref<Pair<K, V>, Node>>
224    where
225        Pair<K, V>: Borrow<Q> + Ord,
226        Q: Ord + ?Sized,
227    {
228        self.set.get(key)
229    }
230    /// Inserts a key-value pair into the map.
231    ///
232    /// If the map did not have this key present, it will be inserted.
233    ///
234    /// Otherwise, the value is updated.
235    ///
236    /// [module-level documentation]: index.html#insert-and-complex-keys
237    ///
238    /// # Examples
239    ///
240    /// Basic usage:
241    ///
242    /// ```
243    /// use wt_indexset::concurrent::map::BTreeMap;
244    ///
245    /// let mut map = BTreeMap::<usize, &str>::new();
246    /// assert_eq!(map.insert(37, "a"), None);
247    /// assert_eq!(map.len() == 0, false);
248    ///
249    /// map.insert(37, "b");
250    /// assert_eq!(map.insert(37, "c"), Some("b"));
251    /// assert_eq!(map.get(&37).and_then(|e| Some(e.get().value)), Some("c"));
252    /// ```
253    pub fn insert(&self, key: K, value: V) -> Option<V> {
254        let new_entry = Pair { key, value };
255
256        self.set
257            .put_cdc(new_entry)
258            .0
259            .and_then(|pair| Some(pair.value))
260    }
261    pub fn checked_insert(&self, key: K, value: V) -> Option<()> {
262        let new_entry = Pair { key, value };
263        self.set.put_cdc_checked(new_entry).ok().map(|_| ())
264    }
265    /// Inserts a key-value pair into the map and returns old value (if it was
266    /// already in set) with [`ChangeEvent`]'s that describes this insert
267    /// action.
268    pub fn insert_cdc(&self, key: K, value: V) -> (Option<V>, Vec<ChangeEvent<Pair<K, V>>>) {
269        let new_entry = Pair { key, value };
270
271        let (old_value, cdc) = self.set.put_cdc(new_entry);
272
273        (old_value.and_then(|pair| Some(pair.value)), cdc)
274    }
275    pub fn checked_insert_cdc(&self, key: K, value: V) -> Option<Vec<ChangeEvent<Pair<K, V>>>> {
276        let new_entry = Pair { key, value };
277        self.set.put_cdc_checked(new_entry).ok().map(|(_, evs)| evs)
278    }
279    /// Removes a key from the map, returning the key and the value if the key
280    /// was previously in the map.
281    ///
282    /// The key may be any borrowed form of the map's key type, but the ordering
283    /// on the borrowed form *must* match the ordering on the key type.
284    ///
285    /// # Examples
286    ///
287    /// Basic usage:
288    ///
289    /// ```
290    /// use wt_indexset::concurrent::map::BTreeMap;
291    ///
292    /// let map = BTreeMap::<usize, &str>::new();
293    /// map.insert(1, "a");
294    /// assert_eq!(map.remove(&1), Some((1, "a")));
295    /// assert_eq!(map.remove(&1), None);
296    /// ```
297    pub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
298    where
299        Pair<K, V>: Borrow<Q> + Ord,
300        Q: Ord + ?Sized,
301    {
302        self.set
303            .remove(key)
304            .and_then(|pair| Some((pair.key, pair.value)))
305    }
306    /// Removes a key from the map, returning the key and the value if the key
307    /// was previously in the map and [`ChangeEvent`]s describing changes caused
308    /// by this action.
309    pub fn remove_cdc<Q>(&self, key: &Q) -> (Option<(K, V)>, Vec<ChangeEvent<Pair<K, V>>>)
310    where
311        Pair<K, V>: Borrow<Q> + Ord,
312        Q: Ord + ?Sized,
313    {
314        let (old_value, cdc) = self.set.remove_cdc(key);
315
316        (old_value.and_then(|pair| Some((pair.key, pair.value))), cdc)
317    }
318    /// Returns the number of elements in the map.
319    ///
320    /// # Examples
321    ///
322    /// Basic usage:
323    ///
324    /// ```
325    /// use wt_indexset::concurrent::map::BTreeMap;
326    ///
327    /// let mut a = BTreeMap::<usize, &str>::new();
328    /// assert_eq!(a.len(), 0);
329    /// a.insert(1, "a");
330    /// assert_eq!(a.len(), 1);
331    /// ```
332    pub fn len(&self) -> usize {
333        self.set.len()
334    }
335    /// Returns the total number of allocated slots across all internal nodes.
336    ///
337    /// This represents the number of key-value pairs the map can hold
338    /// without reallocating memory in its internal vectors.
339    ///
340    /// # Examples
341    ///
342    /// Basic usage:
343    ///
344    /// ```
345    /// use wt_indexset::concurrent::map::BTreeMap;
346    ///
347    /// let mut a = BTreeMap::<usize, &str>::with_maximum_node_size(16);
348    ///
349    /// a.insert(1, "a");
350    /// a.insert(2, "b");
351    ///
352    /// // Capacity remains the same until node is split or reallocated
353    /// assert_eq!(a.capacity(), 16);
354    /// ```
355    pub fn capacity(&self) -> usize {
356        self.set.capacity()
357    }
358    /// Returns the total number of nodes.
359    ///
360    ///
361    /// # Examples
362    ///
363    /// Basic usage:
364    ///
365    /// ```
366    /// use wt_indexset::concurrent::map::BTreeMap;
367    ///
368    /// let mut a = BTreeMap::<usize, &str>::with_maximum_node_size(16);
369    ///
370    /// a.insert(1, "a");
371    /// a.insert(2, "b");
372    ///
373    /// assert_eq!(a.node_count(), 1);
374    /// ```
375    pub fn node_count(&self) -> usize {
376        self.set.node_count()
377    }
378    /// Gets an iterator over the entries of the map, sorted by key.
379    ///
380    /// # Examples
381    ///
382    /// Basic usage:
383    ///
384    /// ```
385    /// use wt_indexset::concurrent::map::BTreeMap;
386    ///
387    /// let mut map = BTreeMap::<usize, &str>::new();
388    /// map.insert(3, "c");
389    /// map.insert(2, "b");
390    /// map.insert(1, "a");
391    ///
392    /// for (key, value) in map.iter() {
393    ///     println!("{key}: {value}");
394    /// }
395    ///
396    /// let (first_key, first_value) = map.iter().next().unwrap();
397    /// assert_eq!((*first_key, *first_value), (1, "a"));
398    /// ```
399    pub fn iter(&self) -> Iter<'_, K, V, Node> {
400        Iter {
401            inner: self.set.iter(),
402        }
403    }
404    /// Constructs a double-ended iterator over a sub-range of elements in the map.
405    /// The simplest way is to use the range syntax `min..max`, thus `range(min..max)` will
406    /// yield elements from min (inclusive) to max (exclusive).
407    /// The range may also be entered as `(Bound<T>, Bound<T>)`, so for example
408    /// `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive
409    /// range from 4 to 10.
410    ///
411    /// # Panics
412    ///
413    /// Panics if range `start > end`.
414    /// Panics if range `start == end` and both bounds are `Excluded`.
415    ///
416    /// # Examples
417    ///
418    /// Basic usage:
419    ///
420    /// ```
421    /// use wt_indexset::concurrent::map::BTreeMap;
422    /// use std::ops::Bound::Included;
423    ///
424    /// let mut map = BTreeMap::<i32, &str>::new();
425    /// map.insert(3, "a");
426    /// map.insert(5, "b");
427    /// map.insert(8, "c");
428    /// for (&key, &value) in map.range::<i32, _>((Included(&4), Included(&8))) {
429    ///     println!("{key}: {value}");
430    /// }
431    /// assert_eq!(Some((&5, &"b")), map.range(4..).next());
432    /// ```
433    pub fn range<Q, R>(&self, range: R) -> Range<'_, K, V, Node>
434    where
435        Pair<K, V>: Borrow<Q>,
436        Q: Ord + ?Sized,
437        R: RangeBounds<Q>,
438    {
439        Range {
440            inner: BTreeSet::range(&self.set, range),
441        }
442    }
443}
444
445#[cfg(test)]
446mod tests {
447    use super::BTreeMap;
448    use super::ChangeEvent;
449    use super::Pair;
450    use crate::BTreeSet;
451    use rand::Rng;
452    use scc::HashMap;
453    use std::fmt::Debug;
454    use std::sync::{Arc, Mutex};
455    use std::thread;
456
457    #[test]
458    fn test_range_edge_cast() {
459        let maximum_node_size = 3;
460        let map = BTreeMap::<usize, &str>::with_maximum_node_size(maximum_node_size);
461
462        map.insert(1usize, "a");
463
464        map.insert(2usize, "b");
465        map.insert(3usize, "c");
466
467        map.insert(4usize, "d");
468        map.insert(5usize, "e");
469
470        map.insert(6usize, "f");
471        map.insert(7usize, "g");
472
473        let mid_range = map.range::<usize, _>(3..5).collect::<BTreeSet<_>>();
474        assert_eq!(
475            mid_range,
476            vec![(&3usize, &"c"), (&4usize, &"d"),]
477                .into_iter()
478                .collect::<BTreeSet<_>>()
479        );
480    }
481
482    #[derive(Debug, Default)]
483    struct PersistedBTreeMap<K, V>
484    where
485        K: Debug + Ord + Clone,
486        V: Debug + Clone + PartialEq,
487    {
488        nodes: std::collections::BTreeMap<K, Vec<Pair<K, V>>>,
489    }
490
491    impl<K: Debug + Ord + Clone, V: Debug + Clone + PartialEq> PersistedBTreeMap<K, V> {
492        fn persist(&mut self, event: &ChangeEvent<Pair<K, V>>) {
493            match event {
494                ChangeEvent::CreateNode {
495                    max_value,
496                    event_id: _,
497                } => {
498                    let node = vec![max_value.clone()];
499                    self.nodes.insert(max_value.key.clone(), node);
500                }
501                ChangeEvent::RemoveNode {
502                    max_value,
503                    event_id: _,
504                } => {
505                    self.nodes.remove(&max_value.key);
506                }
507                ChangeEvent::InsertAt {
508                    max_value,
509                    index,
510                    value,
511                    event_id: _,
512                } => {
513                    if let Some(node) = self.nodes.get_mut(&max_value.key) {
514                        node.insert(*index, value.clone());
515                    }
516                    if max_value.key < value.key {
517                        let node = self.nodes.remove(&max_value.key).unwrap();
518                        self.nodes.insert(value.key.clone(), node);
519                    }
520                }
521                ChangeEvent::RemoveAt {
522                    max_value,
523                    index,
524                    value: _,
525                    event_id: _,
526                } => {
527                    if let Some(node) = self.nodes.get_mut(&max_value.key) {
528                        node.remove(*index);
529                    }
530                }
531                ChangeEvent::SplitNode {
532                    max_value,
533                    split_index,
534                    event_id: _,
535                } => {
536                    if let Some(mut old_node) = self.nodes.remove(&max_value.key) {
537                        let new_node = old_node.split_off(*split_index);
538                        let new_max_value = new_node.last().unwrap();
539                        self.nodes.insert(new_max_value.key.clone(), new_node);
540                        let old_max_value = old_node.last().unwrap();
541                        self.nodes.insert(old_max_value.key.clone(), old_node);
542                    }
543                }
544            }
545        }
546
547        fn contains_pair(&self, key: &K, value: &V) -> bool {
548            for node in self.nodes.values() {
549                if let Ok(pos) = node.binary_search(&Pair {
550                    key: key.clone(),
551                    value: value.clone(),
552                }) {
553                    if node[pos].value == *value {
554                        return true;
555                    }
556                }
557            }
558            false
559        }
560    }
561
562    #[cfg(feature = "cdc")]
563    #[test]
564    fn test_cdc_single_insert() {
565        let map = BTreeMap::<usize, &str>::new();
566        let mut mock_state = PersistedBTreeMap::default();
567
568        let (_, events) = map.insert_cdc(1, "a");
569
570        for event in events {
571            mock_state.persist(&event);
572        }
573
574        assert!(mock_state.contains_pair(&1, &"a"));
575        assert!(map.contains_key(&1));
576        assert_eq!(map.get(&1).unwrap().get().value, "a");
577
578        let expected_state = map
579            .set
580            .index
581            .iter()
582            .map(|e| (e.key().clone().key, e.value().lock_arc().clone()))
583            .collect::<_>();
584        assert_eq!(mock_state.nodes, expected_state);
585    }
586
587    #[cfg(feature = "cdc")]
588    #[test]
589    fn test_cdc_multiple_inserts() {
590        let map = BTreeMap::<usize, String>::new();
591        let mut mock_state = PersistedBTreeMap::default();
592
593        for i in 0..1024 {
594            let (_, events) = map.insert_cdc(i, format!("val{}", i));
595
596            for event in events {
597                mock_state.persist(&event);
598            }
599        }
600
601        for i in 0..1024 {
602            assert!(mock_state.contains_pair(&i, &format!("val{}", i)));
603            assert!(map.contains_key(&i));
604            assert_eq!(map.get(&i).unwrap().get().value, format!("val{}", i));
605        }
606
607        let expected_state = map
608            .set
609            .index
610            .iter()
611            .map(|e| (e.key().clone().key, e.value().lock_arc().clone()))
612            .collect::<_>();
613        assert_eq!(mock_state.nodes, expected_state);
614    }
615
616    #[cfg(feature = "cdc")]
617    #[test]
618    fn test_cdc_updates() {
619        let map = BTreeMap::<usize, &str>::new();
620        let mut mock_state = PersistedBTreeMap::default();
621
622        let (_, events) = map.insert_cdc(1, "a");
623        for event in events {
624            mock_state.persist(&event);
625        }
626
627        let (_, events) = map.insert_cdc(1, "b");
628        for event in events {
629            mock_state.persist(&event);
630        }
631
632        assert!(mock_state.contains_pair(&1, &"b"));
633        assert!(!mock_state.contains_pair(&1, &"a"));
634        assert!(map.contains_key(&1));
635        assert_eq!(map.get(&1).unwrap().get().value, "b");
636
637        let expected_state = map
638            .set
639            .index
640            .iter()
641            .map(|e| (e.key().clone().key, e.value().lock_arc().clone()))
642            .collect::<_>();
643        assert_eq!(mock_state.nodes, expected_state);
644    }
645
646    #[cfg(feature = "cdc")]
647    #[test]
648    fn test_cdc_node_splits() {
649        let map = BTreeMap::<usize, String>::new();
650        let mut mock_state = PersistedBTreeMap::default();
651
652        let n = crate::core::constants::DEFAULT_INNER_SIZE + 10;
653
654        for i in 0..n {
655            let (_, events) = map.insert_cdc(i, format!("val{}", i));
656            for event in events {
657                mock_state.persist(&event);
658            }
659        }
660
661        for i in 0..n {
662            assert!(mock_state.contains_pair(&i, &format!("val{}", i)));
663            assert!(map.contains_key(&i));
664            assert_eq!(map.get(&i).unwrap().get().value, format!("val{}", i));
665        }
666
667        assert!(mock_state.nodes.len() > 1);
668
669        let expected_state = map
670            .set
671            .index
672            .iter()
673            .map(|e| (e.key().clone().key, e.value().lock_arc().clone()))
674            .collect::<_>();
675        assert_eq!(mock_state.nodes, expected_state);
676    }
677
678    #[cfg(feature = "cdc")]
679    #[test]
680    fn test_concurrent_insert_cdc() {
681        let map = Arc::new(BTreeMap::<usize, String>::new());
682        let num_threads = 8;
683        let operations_per_thread = 1000;
684        let mut handles = vec![];
685
686        let test_data: Vec<Vec<(i32, (usize, String))>> = (0..num_threads)
687            .map(|_| {
688                let mut rng = rand::rng();
689                (0..operations_per_thread)
690                    .map(|_| {
691                        let value = rng.random_range(0..100000);
692                        let operation = rng.random_range(0..2);
693                        (operation, (value, format!("val{value}")))
694                    })
695                    .collect()
696            })
697            .collect();
698
699        let expected_values = Arc::new(Mutex::new(HashMap::new()));
700
701        for thread_idx in 0..num_threads {
702            let map_clone = Arc::clone(&map);
703            let expected_values = Arc::clone(&expected_values);
704            let thread_data = test_data[thread_idx].clone();
705
706            let handle = thread::spawn(move || {
707                let mut events = Vec::new();
708                for (operation, (k, v)) in thread_data {
709                    if operation == 0 {
710                        let (_, evs) = map_clone.insert_cdc(k, v.clone());
711                        events.extend(evs);
712                        let _ = expected_values.lock().unwrap().insert(k, v);
713                    }
714                }
715                events
716            });
717            handles.push(handle);
718        }
719
720        let mut final_events = Vec::new();
721        for handle in handles {
722            let thread_events = handle.join().unwrap();
723            final_events.extend(thread_events)
724        }
725        final_events.sort_by(|ev1, ev2| ev1.id().cmp(&ev2.id()));
726
727        let mut mock_state = PersistedBTreeMap::default();
728        for ev in final_events {
729            mock_state.persist(&ev);
730        }
731
732        // let expected_values = expected_values.lock().unwrap();
733        // assert_eq!(mock_state.len(), expected_values.len());
734
735        let expected_state = map
736            .set
737            .index
738            .iter()
739            .map(|e| (e.key().clone().key, e.value().lock_arc().clone()))
740            .collect::<_>();
741        assert_eq!(mock_state.nodes, expected_state);
742    }
743}