Add Comments data structure (#4641)

This commit is contained in:
Micha Reiser 2023-05-30 10:54:55 +02:00 committed by GitHub
parent 6146b75dd0
commit 84a5584888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 698 additions and 0 deletions

View file

@ -209,6 +209,12 @@ impl<K: std::hash::Hash + Eq, V> MultiMap<K, V> {
}
}
pub fn keys(&self) -> Keys<'_, K> {
Keys {
inner: self.index.keys(),
}
}
/// Returns the *leading* parts of `key` in insertion-order.
pub fn leading(&self, key: &K) -> &[V] {
match self.index.get(key) {
@ -759,6 +765,26 @@ impl PartIndex {
}
}
/// Iterator over the keys of a comments multi map
pub struct Keys<'a, K> {
inner: std::collections::hash_map::Keys<'a, K, Entry>,
}
impl<'a, K> Iterator for Keys<'a, K> {
type Item = &'a K;
fn next(&mut self) -> Option<Self::Item> {
self.inner.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}
impl<K> ExactSizeIterator for Keys<'_, K> {}
impl<K> FusedIterator for Keys<'_, K> {}
#[cfg(test)]
mod tests {
use crate::comments::map::MultiMap;