mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Add Comments
data structure (#4641)
This commit is contained in:
parent
6146b75dd0
commit
84a5584888
5 changed files with 698 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue