summaryrefslogtreecommitdiffstats
path: root/src/collector
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2018-04-14 20:22:02 +0900
committerPaul Masurel <paul.masurel@gmail.com>2018-04-14 20:22:02 +0900
commita1c07bf4573ab11d8dcd6c7c41724048d91ef29e (patch)
treec68853bea800856c15e1dd5274d5c62f587f7296 /src/collector
parent9de74b68d1b6f45188a1acc24cb37341781cde95 (diff)
Added iterator for facet collector
Diffstat (limited to 'src/collector')
-rw-r--r--src/collector/facet_collector.rs34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/collector/facet_collector.rs b/src/collector/facet_collector.rs
index f94d343..bc0c46c 100644
--- a/src/collector/facet_collector.rs
+++ b/src/collector/facet_collector.rs
@@ -432,11 +432,29 @@ pub struct FacetCounts {
facet_counts: BTreeMap<Facet, u64>,
}
+
+use std::collections::btree_map;
+
+struct FacetChildIterator<'a> {
+ underlying: btree_map::Range<'a, Facet, u64>,
+}
+
+impl<'a> Iterator for FacetChildIterator<'a> {
+
+ type Item = (&'a Facet, u64);
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.underlying
+ .next()
+ .map(|(facet, count)| (facet, *count))
+ }
+}
+
+
impl FacetCounts {
- #[allow(needless_lifetimes)] //< compiler fails if we remove the lifetime
- pub fn get<'a, T>(&'a self, facet_from: T) -> impl Iterator<Item = (&'a Facet, u64)>
- where
- Facet: From<T>,
+
+ pub fn get<T>(&self, facet_from: T) -> FacetChildIterator //impl Iterator<Item = (&'a Facet, u64)>
+ where Facet: From<T>
{
let facet = Facet::from(facet_from);
let left_bound = Bound::Excluded(facet.clone());
@@ -448,10 +466,10 @@ impl FacetCounts {
let facet_after = Facet::from_encoded(facet_after_bytes);
Bound::Excluded(facet_after)
};
-
- self.facet_counts
- .range((left_bound, right_bound))
- .map(|(facet, count)| (facet, *count))
+ let underlying: btree_map::Range<_, _> = self.facet_counts.range((left_bound, right_bound));
+ FacetChildIterator {
+ underlying
+ }
}
pub fn top_k<T>(&self, facet: T, k: usize) -> Vec<(&Facet, u64)>