Skip to content

Commit edf0530

Browse files
committed
Add contains_key to SortedIndexMultiMap
1 parent 5157d93 commit edf0530

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: compiler/rustc_data_structures/src/sorted_map/index_map.rs

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
100100
(k == &key).then_some((i, v))
101101
})
102102
}
103+
104+
#[inline]
105+
pub fn contains_key(&self, key: K) -> bool {
106+
self.get_by_key(key).next().is_some()
107+
}
103108
}
104109

105110
impl<I: Idx, K: Eq, V: Eq> Eq for SortedIndexMultiMap<I, K, V> {}

Diff for: compiler/rustc_data_structures/src/sorted_map/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ fn test_sorted_index_multi_map() {
1717
assert_eq!(set.get_by_key(3).copied().collect::<Vec<_>>(), vec![0]);
1818
assert!(set.get_by_key(4).next().is_none());
1919

20+
// `contains_key` works
21+
assert!(set.contains_key(3));
22+
assert!(!set.contains_key(4));
23+
2024
// `get_by_key` returns items in insertion order.
2125
let twos: Vec<_> = set.get_by_key_enumerated(2).collect();
2226
let idxs: Vec<usize> = twos.iter().map(|(i, _)| *i).collect();

0 commit comments

Comments
 (0)