diff options
author | Till Höppner | 2016-02-25 06:58:22 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-25 06:58:22 +0100 |
commit | cd15d4f8de1ee9bc6d00fb0a08659ca2c74d2e2d (patch) | |
tree | 66b6a4fff228446fc46f4b47ba3b8551ba46e8b2 /src/ageset.rs | |
parent | 9f5dd9dad6b13476bab2c6eb3c6528f8ad49311a (diff) | |
download | ilc-cd15d4f8de1ee9bc6d00fb0a08659ca2c74d2e2d.tar.gz ilc-cd15d4f8de1ee9bc6d00fb0a08659ca2c74d2e2d.tar.xz ilc-cd15d4f8de1ee9bc6d00fb0a08659ca2c74d2e2d.zip |
Update Cargo.toml files with more metadata
Diffstat (limited to 'src/ageset.rs')
-rw-r--r-- | src/ageset.rs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/ageset.rs b/src/ageset.rs deleted file mode 100644 index c97240f..0000000 --- a/src/ageset.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::collections::HashSet; -use std::hash::Hash; - -use blist::BList; - -/// So... this is a rather weird thing. -/// It allows to semi-efficiently check the oldest (earliest insertion) -/// elements for certain criteria and remove them in the order of insertion -/// if the criteria is met. -pub struct AgeSet<T> { - fifo: BList<T>, - set: HashSet<T>, -} - -impl<T> AgeSet<T> - where T: Eq + Hash + Clone -{ - pub fn new() -> Self { - AgeSet { - fifo: BList::new(), - set: HashSet::new(), - } - } - - pub fn contains(&self, t: &T) -> bool { - self.set.contains(t) - } - - pub fn prune<F>(&mut self, kill: F) - where F: Fn(&T) -> bool - { - while let Some(ref e) = self.fifo.front().map(T::clone) { - if kill(&e) { - let removed = self.fifo.pop_front().unwrap(); - self.set.remove(&e); - assert!(*e == removed); - } else { - break; - } - } - } - - pub fn push(&mut self, t: T) { - self.fifo.push_back(t.clone()); - self.set.insert(t); - } -} |