Add contains_key to SortedIndexMultiMap
This commit is contained in:
parent
5157d938c4
commit
edf053036f
2 changed files with 9 additions and 0 deletions
|
@ -100,6 +100,11 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
|
||||||
(k == &key).then_some((i, v))
|
(k == &key).then_some((i, v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn contains_key(&self, key: K) -> bool {
|
||||||
|
self.get_by_key(key).next().is_some()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Idx, K: Eq, V: Eq> Eq for SortedIndexMultiMap<I, K, V> {}
|
impl<I: Idx, K: Eq, V: Eq> Eq for SortedIndexMultiMap<I, K, V> {}
|
||||||
|
|
|
@ -17,6 +17,10 @@ fn test_sorted_index_multi_map() {
|
||||||
assert_eq!(set.get_by_key(3).copied().collect::<Vec<_>>(), vec![0]);
|
assert_eq!(set.get_by_key(3).copied().collect::<Vec<_>>(), vec![0]);
|
||||||
assert!(set.get_by_key(4).next().is_none());
|
assert!(set.get_by_key(4).next().is_none());
|
||||||
|
|
||||||
|
// `contains_key` works
|
||||||
|
assert!(set.contains_key(3));
|
||||||
|
assert!(!set.contains_key(4));
|
||||||
|
|
||||||
// `get_by_key` returns items in insertion order.
|
// `get_by_key` returns items in insertion order.
|
||||||
let twos: Vec<_> = set.get_by_key_enumerated(2).collect();
|
let twos: Vec<_> = set.get_by_key_enumerated(2).collect();
|
||||||
let idxs: Vec<usize> = twos.iter().map(|(i, _)| *i).collect();
|
let idxs: Vec<usize> = twos.iter().map(|(i, _)| *i).collect();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue