diff --git a/common/src/bitset.rs b/common/src/bitset.rs index 527abed9b..84c936a61 100644 --- a/common/src/bitset.rs +++ b/common/src/bitset.rs @@ -64,19 +64,19 @@ impl TinySet { } #[inline] - /// Returns true iff the `TinySet` contains the element `el`. - pub fn contains(self, el: u32) -> bool { - !self.intersect(TinySet::singleton(el)).is_empty() + /// Returns true iff the `TinySet` bit is set at position `pos`. + pub fn contains(self, pos: u32) -> bool { + !self.intersect(TinySet::singleton(pos)).is_empty() } #[inline] - /// Returns the number of elements in the TinySet. - pub fn len(self) -> u32 { + /// Returns the number of set bits in the TinySet. + pub fn num_set(self) -> u32 { self.0.count_ones() } #[inline] - /// Returns the number of elements in the TinySet. + /// Returns the number of unset bits in the TinySet. pub fn num_unset(self) -> u32 { self.0.count_zeros() } @@ -87,11 +87,11 @@ impl TinySet { TinySet(self.0 & other.0) } - /// Creates a new `TinySet` containing only one element + /// Creates a new `TinySet` with only one bit set at `pos`. /// within `[0; 64[` #[inline] - pub fn singleton(el: u32) -> TinySet { - TinySet(1u64 << u64::from(el)) + pub fn singleton(pos: u32) -> TinySet { + TinySet(1u64 << u64::from(pos)) } /// Insert a new element within [0..64) @@ -203,7 +203,7 @@ impl BitSet { let mut tinysets = vec![]; for chunk in data.chunks_exact(8) { let tinyset = TinySet::deserialize(chunk.try_into().unwrap())?; - len += tinyset.len() as u64; + len += tinyset.num_set() as u64; tinysets.push(tinyset); } Ok(BitSet { diff --git a/src/query/union.rs b/src/query/union.rs index cf7b4d956..da6da15c0 100644 --- a/src/query/union.rs +++ b/src/query/union.rs @@ -219,14 +219,18 @@ where } let mut count = self.bitsets[self.cursor..HORIZON_NUM_TINYBITSETS] .iter() - .map(|bitset| bitset.len()) + .map(|bitset| bitset.num_set()) .sum::() + 1; for bitset in self.bitsets.iter_mut() { bitset.clear(); } while self.refill() { - count += self.bitsets.iter().map(|bitset| bitset.len()).sum::(); + count += self + .bitsets + .iter() + .map(|bitset| bitset.num_set()) + .sum::(); for bitset in self.bitsets.iter_mut() { bitset.clear(); }