Skip to content

Commit

Permalink
Merge pull request #115 from oliverdding/oliver-insert-remove-range-b…
Browse files Browse the repository at this point in the history
…ounds

Insert/remove range with bounds
  • Loading branch information
Kerollmops authored Oct 18, 2021
2 parents 86df2e4 + 87d2ae0 commit 14376a0
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 261 deletions.
19 changes: 5 additions & 14 deletions src/bitmap/container.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{fmt, ops::Range};
use std::fmt;
use std::ops::RangeInclusive;

use super::store::{self, Store};
use super::util;
Expand Down Expand Up @@ -38,13 +39,7 @@ impl Container {
}
}

pub fn insert_range(&mut self, range: Range<u16>) -> u64 {
// If the range is larger than the array limit, skip populating the
// array to then have to convert it to a bitmap anyway.
if matches!(self.store, Store::Array(_)) && range.end - range.start > ARRAY_LIMIT as u16 {
self.store = self.store.to_bitmap()
}

pub fn insert_range(&mut self, range: RangeInclusive<u16>) -> u64 {
let inserted = self.store.insert_range(range);
self.len += inserted;
self.ensure_correct_store();
Expand All @@ -68,12 +63,8 @@ impl Container {
}
}

pub fn remove_range(&mut self, start: u32, end: u32) -> u64 {
debug_assert!(start <= end);
if start == end {
return 0;
}
let result = self.store.remove_range(start, end);
pub fn remove_range(&mut self, range: RangeInclusive<u16>) -> u64 {
let result = self.store.remove_range(range);
self.len -= result;
self.ensure_correct_store();
result
Expand Down
Loading

0 comments on commit 14376a0

Please sign in to comment.