Refinements to BTreeBag
This commit is contained in:
parent
61005d308f
commit
4eb35ca9b8
|
@ -1,6 +1,5 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::collections::btree_map::Iter;
|
use std::collections::btree_map::{Iter, Keys, Entry};
|
||||||
use std::collections::btree_map::Keys;
|
|
||||||
use std::iter::{FromIterator, IntoIterator};
|
use std::iter::{FromIterator, IntoIterator};
|
||||||
|
|
||||||
type Count = i32;
|
type Count = i32;
|
||||||
|
@ -12,6 +11,7 @@ pub enum Net {
|
||||||
PresentToPresent,
|
PresentToPresent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
// Allows negative counts - a "delta"
|
// Allows negative counts - a "delta"
|
||||||
pub struct BTreeBag<V: std::cmp::Ord> {
|
pub struct BTreeBag<V: std::cmp::Ord> {
|
||||||
counts: BTreeMap<V, Count>,
|
counts: BTreeMap<V, Count>,
|
||||||
|
@ -63,6 +63,10 @@ impl<V: std::cmp::Ord> BTreeBag<V> {
|
||||||
pub fn keys(&self) -> Keys<V, Count> {
|
pub fn keys(&self) -> Keys<V, Count> {
|
||||||
self.counts.keys()
|
self.counts.keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn entry(&mut self, key: V) -> Entry<V, Count> {
|
||||||
|
self.counts.entry(key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V: std::cmp::Ord> IntoIterator for &'a BTreeBag<V> {
|
impl<'a, V: std::cmp::Ord> IntoIterator for &'a BTreeBag<V> {
|
||||||
|
|
Loading…
Reference in New Issue