Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert/remove range with bounds #115

Merged
merged 6 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Kerollmops marked this conversation as resolved.
Show resolved Hide resolved

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