summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorJason Wolfe <jasonwolfe@utexas.edu>2018-10-15 09:04:36 +0900
committerPaul Masurel <paul.masurel@gmail.com>2018-10-15 09:04:36 +0900
commit0098e3d4285967555c605de955a397fba06a6c6c (patch)
tree32793cc444645f67b4b9038c06f36038f9448fce /src/common
parent69d5e4b9b170e93a050ae2f508a4f448340bffe1 (diff)
Compute space usage of a Searcher / SegmentReader / CompositeFile (#282)
* Compute space usage of a Searcher / SegmentReader / CompositeFile * Fix typo * Add serde Serialize/Deserialize for all the SpaceUsage structs * Fix indexing * Public methods for consuming space usage information * #281: Add a space usage method that takes a SegmentComponent to support code that is unaware of particular segment components, and to make it more likely to update methods when a new component type is added. * Add support for space usage computation of positions skip index file (#281) * Add some tests for space usage computation (#281)
Diffstat (limited to 'src/common')
-rw-r--r--src/common/composite_file.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/common/composite_file.rs b/src/common/composite_file.rs
index e7d657b..0cdfdff 100644
--- a/src/common/composite_file.rs
+++ b/src/common/composite_file.rs
@@ -4,6 +4,8 @@ use common::VInt;
use directory::ReadOnlySource;
use directory::WritePtr;
use schema::Field;
+use space_usage::PerFieldSpaceUsage;
+use space_usage::FieldUsage;
use std::collections::HashMap;
use std::io::Write;
use std::io::{self, Read};
@@ -166,6 +168,16 @@ impl CompositeFile {
.get(&FileAddr { field, idx })
.map(|&(from, to)| self.data.slice(from, to))
}
+
+ pub fn space_usage(&self) -> PerFieldSpaceUsage {
+ let mut fields = HashMap::new();
+ for (&field_addr, &(start, end)) in self.offsets_index.iter() {
+ fields.entry(field_addr.field)
+ .or_insert_with(|| FieldUsage::empty(field_addr.field))
+ .add_field_idx(field_addr.idx, end - start);
+ }
+ PerFieldSpaceUsage::new(fields)
+ }
}
#[cfg(test)]