|
1 | 1 | use core::alloc::Allocator; |
2 | | -use core::iter::FusedIterator; |
3 | 2 |
|
4 | | -use super::merge_iter::MergeIterInner; |
5 | 3 | use super::node::{self, Root}; |
6 | 4 |
|
7 | 5 | impl<K, V> Root<K, V> { |
8 | | - /// Appends all key-value pairs from the union of two ascending iterators, |
9 | | - /// incrementing a `length` variable along the way. The latter makes it |
10 | | - /// easier for the caller to avoid a leak when a drop handler panicks. |
11 | | - /// |
12 | | - /// If both iterators produce the same key, this method drops the pair from |
13 | | - /// the left iterator and appends the pair from the right iterator. |
14 | | - /// |
15 | | - /// If you want the tree to end up in a strictly ascending order, like for |
16 | | - /// a `BTreeMap`, both iterators should produce keys in strictly ascending |
17 | | - /// order, each greater than all keys in the tree, including any keys |
18 | | - /// already in the tree upon entry. |
19 | | - pub(super) fn append_from_sorted_iters<I, A: Allocator + Clone>( |
20 | | - &mut self, |
21 | | - left: I, |
22 | | - right: I, |
23 | | - length: &mut usize, |
24 | | - alloc: A, |
25 | | - ) where |
26 | | - K: Ord, |
27 | | - I: Iterator<Item = (K, V)> + FusedIterator, |
28 | | - { |
29 | | - // We prepare to merge `left` and `right` into a sorted sequence in linear time. |
30 | | - let iter = MergeIter(MergeIterInner::new(left, right)); |
31 | | - |
32 | | - // Meanwhile, we build a tree from the sorted sequence in linear time. |
33 | | - self.bulk_push(iter, length, alloc) |
34 | | - } |
35 | | - |
36 | 6 | /// Pushes all key-value pairs to the end of the tree, incrementing a |
37 | 7 | /// `length` variable along the way. The latter makes it easier for the |
38 | 8 | /// caller to avoid a leak when the iterator panicks. |
@@ -94,24 +64,3 @@ impl<K, V> Root<K, V> { |
94 | 64 | self.fix_right_border_of_plentiful(); |
95 | 65 | } |
96 | 66 | } |
97 | | - |
98 | | -// An iterator for merging two sorted sequences into one |
99 | | -struct MergeIter<K, V, I: Iterator<Item = (K, V)>>(MergeIterInner<I>); |
100 | | - |
101 | | -impl<K: Ord, V, I> Iterator for MergeIter<K, V, I> |
102 | | -where |
103 | | - I: Iterator<Item = (K, V)> + FusedIterator, |
104 | | -{ |
105 | | - type Item = (K, V); |
106 | | - |
107 | | - /// If two keys are equal, returns the key from the left and the value from the right. |
108 | | - fn next(&mut self) -> Option<(K, V)> { |
109 | | - let (a_next, b_next) = self.0.nexts(|a: &(K, V), b: &(K, V)| K::cmp(&a.0, &b.0)); |
110 | | - match (a_next, b_next) { |
111 | | - (Some((a_k, _)), Some((_, b_v))) => Some((a_k, b_v)), |
112 | | - (Some(a), None) => Some(a), |
113 | | - (None, Some(b)) => Some(b), |
114 | | - (None, None) => None, |
115 | | - } |
116 | | - } |
117 | | -} |
0 commit comments