Refinements to BTreeBag

This commit is contained in:
Tony Garnock-Jones 2019-10-20 22:24:44 +01:00
parent 61005d308f
commit 4eb35ca9b8
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,5 @@
use std::collections::BTreeMap;
use std::collections::btree_map::Iter;
use std::collections::btree_map::Keys;
use std::collections::btree_map::{Iter, Keys, Entry};
use std::iter::{FromIterator, IntoIterator};
type Count = i32;
@ -12,6 +11,7 @@ pub enum Net {
PresentToPresent,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
// Allows negative counts - a "delta"
pub struct BTreeBag<V: std::cmp::Ord> {
counts: BTreeMap<V, Count>,
@ -63,6 +63,10 @@ impl<V: std::cmp::Ord> BTreeBag<V> {
pub fn keys(&self) -> Keys<V, Count> {
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> {