@@ -34,39 +34,47 @@ pub struct SortedIndexMultiMap<I: Idx, K, V> {
34
34
}
35
35
36
36
impl < I : Idx , K : Ord , V > SortedIndexMultiMap < I , K , V > {
37
+ #[ inline]
37
38
pub fn new ( ) -> Self {
38
39
SortedIndexMultiMap { items : IndexVec :: new ( ) , idx_sorted_by_item_key : Vec :: new ( ) }
39
40
}
40
41
42
+ #[ inline]
41
43
pub fn len ( & self ) -> usize {
42
44
self . items . len ( )
43
45
}
44
46
47
+ #[ inline]
45
48
pub fn is_empty ( & self ) -> bool {
46
49
self . items . is_empty ( )
47
50
}
48
51
49
52
/// Returns an iterator over the items in the map in insertion order.
53
+ #[ inline]
50
54
pub fn into_iter ( self ) -> impl DoubleEndedIterator < Item = ( K , V ) > {
51
55
self . items . into_iter ( )
52
56
}
53
57
54
58
/// Returns an iterator over the items in the map in insertion order along with their indices.
59
+ #[ inline]
55
60
pub fn into_iter_enumerated ( self ) -> impl DoubleEndedIterator < Item = ( I , ( K , V ) ) > {
56
61
self . items . into_iter_enumerated ( )
57
62
}
58
63
59
64
/// Returns an iterator over the items in the map in insertion order.
65
+ #[ inline]
60
66
pub fn iter ( & self ) -> impl ' _ + DoubleEndedIterator < Item = ( & K , & V ) > {
61
67
self . items . iter ( ) . map ( |( ref k, ref v) | ( k, v) )
62
68
}
63
69
64
70
/// Returns an iterator over the items in the map in insertion order along with their indices.
71
+ #[ inline]
65
72
pub fn iter_enumerated ( & self ) -> impl ' _ + DoubleEndedIterator < Item = ( I , ( & K , & V ) ) > {
66
73
self . items . iter_enumerated ( ) . map ( |( i, ( ref k, ref v) ) | ( i, ( k, v) ) )
67
74
}
68
75
69
76
/// Returns the item in the map with the given index.
77
+ #[ inline]
70
78
pub fn get ( & self , idx : I ) -> Option < & ( K , V ) > {
71
79
self . items . get ( idx)
72
80
}
@@ -75,6 +83,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
75
83
///
76
84
/// If there are multiple items that are equivalent to `key`, they will be yielded in
77
85
/// insertion order.
86
+ #[ inline]
78
87
pub fn get_by_key ( & ' a self , key : K ) -> impl ' a + Iterator < Item = & ' a V > {
79
88
self . get_by_key_enumerated ( key) . map ( |( _, v) | v)
80
89
}
@@ -84,6 +93,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
84
93
///
85
94
/// If there are multiple items that are equivalent to `key`, they will be yielded in
86
95
/// insertion order.
96
+ #[ inline]
87
97
pub fn get_by_key_enumerated ( & ' a self , key : K ) -> impl ' _ + Iterator < Item = ( I , & V ) > {
88
98
let lower_bound = self . idx_sorted_by_item_key . partition_point ( |& i| self . items [ i] . 0 < key) ;
89
99
self . idx_sorted_by_item_key [ lower_bound..] . iter ( ) . map_while ( move |& i| {
0 commit comments