Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Aug 16, 2024
1 parent 93e9011 commit 8b38547
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl<const B: usize> BitSet<B> {
bitset
}

/// Convert from Inline to Heap representation.
fn overflow(&mut self, value: u32) {
/// Convert from Inline to Heap, if needed, and resize the Heap vector, if needed.
fn resize(&mut self, value: u32) {
let num_blocks_needed = (value / 64) + 1;
match self {
Self::Inline(blocks) => {
Expand All @@ -47,14 +47,14 @@ impl<const B: usize> BitSet<B> {
}
}

fn get_blocks_mut(&mut self) -> &mut [u64] {
fn blocks_mut(&mut self) -> &mut [u64] {
match self {
Self::Inline(blocks) => blocks.as_mut_slice(),
Self::Heap(blocks) => blocks.as_mut_slice(),
}
}

fn get_blocks(&self) -> &[u64] {
fn blocks(&self) -> &[u64] {
match self {
Self::Inline(blocks) => blocks.as_slice(),
Self::Heap(blocks) => blocks.as_slice(),
Expand All @@ -67,19 +67,19 @@ impl<const B: usize> BitSet<B> {
pub(super) fn insert(&mut self, value: u32) -> bool {
let value_usize = value as usize;
let (block, index) = (value_usize / 64, value_usize % 64);
if block >= self.get_blocks().len() {
self.overflow(value);
if block >= self.blocks().len() {
self.resize(value);
}
let blocks = self.get_blocks_mut();
let blocks = self.blocks_mut();
let missing = blocks[block] & (1 << index) == 0;
blocks[block] |= 1 << index;
missing
}

/// Intersect in-place with another [`BitSet`].
pub(super) fn intersect(&mut self, other: &BitSet<B>) {
let my_blocks = self.get_blocks_mut();
let other_blocks = other.get_blocks();
let my_blocks = self.blocks_mut();
let other_blocks = other.blocks();
let min_len = my_blocks.len().min(other_blocks.len());
for i in 0..min_len {
my_blocks[i] &= other_blocks[i];
Expand All @@ -91,7 +91,7 @@ impl<const B: usize> BitSet<B> {

/// Return an iterator over the values (in ascending order) in this [`BitSet`].
pub(super) fn iter(&self) -> BitSetIterator<'_, B> {
let blocks = self.get_blocks();
let blocks = self.blocks();
BitSetIterator {
blocks,
current_block_index: 0,
Expand Down

0 comments on commit 8b38547

Please sign in to comment.