Skip to content

Commit

Permalink
implemented insert_push_back()
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed Jan 20, 2024
1 parent 28fba3d commit e83347d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ btree_monstrousity = { version = "0.0.4", features = [
], default-features = false }
either = { version = "1.9.0", default-features = false }
itertools = { version = "0.12.0", default-features = false }
smallvec = { version = "1.13.1", default-features = false }

[dev-dependencies]
pretty_assertions = "1.4.0"
Expand Down
25 changes: 21 additions & 4 deletions src/zosdit/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ use core::marker::PhantomData;

use btree_monstrousity::btree_map::SearchBoundCustom;
use btree_monstrousity::BTreeMap;
use smallvec::SmallVec;

use crate::utils::double_comp;
use crate::{IntervalType, PointType};

const SMALL_VEC_ARRAY_SIZE: usize = 2;

/// A Zero Overlap Sequential Discrete Interval Tree Map Data-Structure based off [`NoditMap`] and
/// [`SmallVec`]
///
Expand All @@ -23,7 +27,7 @@ use crate::{IntervalType, PointType};
/// Phrasing it another way: `I` is the point type, `K` is the interval type, and `V` is the value type.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ZosditMap<I, K, V> {
inner: BTreeMap<K, V>,
inner: BTreeMap<K, SmallVec<[V; SMALL_VEC_ARRAY_SIZE]>>,
phantom: PhantomData<I>,
}

Expand Down Expand Up @@ -66,10 +70,19 @@ where
/// internal `SmallVec` for that entry.
pub fn insert_push_back(
&mut self,
interval: I,
interval: K,
value: V,
) -> Result<(), NonZeroOverlapError<V>> {
todo!()
if !self.is_zero_overlap(interval) {
Err(NonZeroOverlapError { value })
} else {
self.inner
.entry(interval, double_comp())
.or_default()
.push(value);

Ok(())
}
}

/// Returns `true` if the given interval zero-overlaps the intervals in
Expand Down Expand Up @@ -144,7 +157,11 @@ mod tests {
for ((start, end), map_intervals, expected) in test_cases {
let mut map = ZosditMap::new();
for (mi_start, mi_end) in map_intervals.clone() {
map.inner.insert(ii(mi_start, mi_end), (), double_comp());
map.inner.insert(
ii(mi_start, mi_end),
SmallVec::<[(); 2]>::new(),
double_comp(),
);
}

let search_interval = ii(start, end);
Expand Down

0 comments on commit e83347d

Please sign in to comment.