Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 committed Sep 19, 2024
1 parent f8b199e commit 44c954c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions encodings/roaring/src/boolean/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ impl ArrayStatisticsCompute for RoaringBoolArray {
}
}

// Underlying bitset, length in bits, cardinality (true count) of the bitset
struct BitmapStats(Bitset, usize, u64);

impl ArrayStatisticsCompute for BitmapStats {
fn compute_statistics(&self, _stat: Stat) -> VortexResult<StatsSet> {
let bitset_slice = self.0.as_slice();
// This is a weird case where the bitset is full of false values
// sometimes it will not allocate any underlying storage
// TODO(robert): This likely can be simplified after https://github.com/RoaringBitmap/CRoaring/issues/660
if bitset_slice.is_empty() {
return Ok(StatsSet::from(HashMap::from([
(Stat::IsSorted, true.into()),
Expand All @@ -53,7 +55,7 @@ impl ArrayStatisticsCompute for BitmapStats {
}

struct RoaringBoolStatsAccumulator {
last: bool,
prev: bool,
is_sorted: bool,
run_count: usize,
len: usize,
Expand All @@ -62,7 +64,7 @@ struct RoaringBoolStatsAccumulator {
impl RoaringBoolStatsAccumulator {
fn new(first_value: bool) -> Self {
Self {
last: first_value,
prev: first_value,
is_sorted: true,
run_count: 1,
len: 0,
Expand All @@ -74,12 +76,13 @@ impl RoaringBoolStatsAccumulator {
self.len += len;
for i in 0..len {
let current = ((next >> i) & 1) == 1;
if !current & self.last {
// Booleans are sorted true > false so we aren't sorted if we switched from true to false value
if !current && self.prev {
self.is_sorted = false;
}
if current != self.last {
if current != self.prev {
self.run_count += 1;
self.last = current;
self.prev = current;
}
}
}
Expand Down

0 comments on commit 44c954c

Please sign in to comment.