diff --git a/Cargo.lock b/Cargo.lock
index a3de6f6..046e3fe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,9 +10,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "btree_monstousity"
-version = "0.0.3"
+version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1bcfb39dbdc98ba2984b575608c94a871f111960a813a23e88b0ac3d62fd274"
+checksum = "a596671a3fb8cd1899005c5cdc5ce442fe4d0153abbe12917171f7d435831563"
dependencies = [
"cfg-if",
"rustversion",
diff --git a/Cargo.toml b/Cargo.toml
index 8814fb3..f10a43d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ serde = {version = "1.0.148", features = ["derive"]}
itertools = "0.10.5"
labels = "0.0.2"
pretty_assertions = "1.3.0"
-btree_monstousity = "0.0.3"
+btree_monstousity = "0.0.4"
[dev-dependencies]
ordered-float = "3.4.0"
diff --git a/src/delete_me.rs b/src/delete_me.rs
new file mode 100644
index 0000000..3b1039e
--- /dev/null
+++ b/src/delete_me.rs
@@ -0,0 +1 @@
+use std::ops::RangeBounds;
diff --git a/src/helpers.rs b/src/helpers.rs
index 477a460..537e996 100644
--- a/src/helpers.rs
+++ b/src/helpers.rs
@@ -34,9 +34,9 @@ where
B: Ord,
{
if bound_ord < BoundOrd::start(range_bounds.start_bound()) {
- Ordering::Greater
- } else if bound_ord > BoundOrd::end(range_bounds.end_bound()) {
Ordering::Less
+ } else if bound_ord > BoundOrd::end(range_bounds.end_bound()) {
+ Ordering::Greater
} else {
Ordering::Equal
}
diff --git a/src/lib.rs b/src/lib.rs
index ceed3bf..9cc0283 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -231,6 +231,7 @@ pub(crate) mod bound_ord;
pub(crate) mod helpers;
pub mod range_bounds_map;
+pub mod delete_me;
//pub mod range_bounds_set;
pub mod try_from_bounds;
diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs
index 1f71852..83f1c6f 100644
--- a/src/range_bounds_map.rs
+++ b/src/range_bounds_map.rs
@@ -17,6 +17,7 @@ You should have received a copy of the GNU Affero General Public License
along with range_bounds_map. If not, see .
*/
+use std::cmp::Ordering;
use std::fmt::{self, Debug};
use std::iter::once;
use std::marker::PhantomData;
@@ -358,7 +359,20 @@ where
range_bounds: K,
value: V,
) -> Result<(), OverlapError> {
- todo!()
+ if self.overlaps((range_bounds.start_bound(), range_bounds.end_bound()))
+ {
+ return Err(OverlapError);
+ }
+
+ let double_comp = |inner_range_bounds: &K, new_range_bounds: &K| {
+ let retult = BoundOrd::start(new_range_bounds.start_bound())
+ .cmp(&BoundOrd::start(inner_range_bounds.start_bound()));
+ retult
+ };
+
+ self.inner.insert(range_bounds, value, double_comp);
+
+ return Ok(());
}
/// Returns `true` if the given `RangeBounds` overlaps any of the
@@ -390,7 +404,7 @@ where
where
Q: RangeBounds,
{
- todo!()
+ self.overlapping(range_bounds).next().is_some()
}
/// Returns an iterator over every (`RangeBounds`, `Value`) entry
@@ -430,18 +444,8 @@ where
where
Q: RangeBounds,
{
- let lower_comp = |inner_range_bounds: &K| {
- cmp_range_bounds_with_bound_ord(
- inner_range_bounds,
- BoundOrd::start(range_bounds.start_bound()),
- )
- };
- let upper_comp = |inner_range_bounds: &K| {
- cmp_range_bounds_with_bound_ord(
- inner_range_bounds,
- BoundOrd::end(range_bounds.end_bound()),
- )
- };
+ let lower_comp = comp_start(range_bounds.start_bound());
+ let upper_comp = comp_end(range_bounds.end_bound());
let lower_bound = SearchBoundCustom::Included;
let upper_bound = SearchBoundCustom::Included;
@@ -471,7 +475,7 @@ where
/// ```
#[trivial]
pub fn get_at_point(&self, point: &I) -> Option<&V> {
- todo!()
+ self.get_entry_at_point(point).map(|(key, value)| value)
}
/// Returns `true` if the map contains a `RangeBounds` that
@@ -494,7 +498,7 @@ where
/// ```
#[trivial]
pub fn contains_point(&self, point: &I) -> bool {
- todo!()
+ self.get_entry_at_point(point).is_some()
}
/// Returns a mutable reference to the `Value` corresponding to
@@ -514,8 +518,8 @@ where
/// assert_eq!(map.get_at_point(&1), Some(&true));
/// ```
#[tested]
- pub fn get_at_point_mut(&mut self, point: I) -> Option<&mut V> {
- todo!()
+ pub fn get_at_point_mut(&mut self, point: &I) -> Option<&mut V> {
+ self.inner.get_mut(comp_start(Bound::Included(point)))
}
/// Returns an (`RangeBounds`, `Value`) entry corresponding to the
@@ -538,7 +542,7 @@ where
/// ```
#[trivial]
pub fn get_entry_at_point(&self, point: &I) -> Option<(&K, &V)> {
- todo!()
+ self.inner.get_key_value(comp_start(Bound::Included(point)))
}
/// Returns an iterator over every (`RangeBounds`, `Value`) entry
@@ -1647,3 +1651,28 @@ where
todo!()
}
}
+
+fn comp_start(bound: Bound<&I>) -> impl FnMut(&K) -> Ordering + '_
+where
+ I: Ord,
+ K: RangeBounds,
+{
+ move |inner_range_bounds: &K| {
+ cmp_range_bounds_with_bound_ord(
+ inner_range_bounds,
+ BoundOrd::start(bound),
+ )
+ }
+}
+fn comp_end(bound: Bound<&I>) -> impl FnMut(&K) -> Ordering + '_
+where
+ I: Ord,
+ K: RangeBounds,
+{
+ move |inner_range_bounds: &K| {
+ cmp_range_bounds_with_bound_ord(
+ inner_range_bounds,
+ BoundOrd::end(bound),
+ )
+ }
+}