diff --git a/Cargo.lock b/Cargo.lock
index c21e3bf..a3de6f6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8,6 +8,22 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+[[package]]
+name = "btree_monstousity"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1bcfb39dbdc98ba2984b575608c94a871f111960a813a23e88b0ac3d62fd274"
+dependencies = [
+ "cfg-if",
+ "rustversion",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
[[package]]
name = "ctor"
version = "0.1.26"
@@ -110,6 +126,7 @@ dependencies = [
name = "range_bounds_map"
version = "0.1.1"
dependencies = [
+ "btree_monstousity",
"either",
"itertools",
"labels",
@@ -118,6 +135,12 @@ dependencies = [
"serde",
]
+[[package]]
+name = "rustversion"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
+
[[package]]
name = "serde"
version = "1.0.150"
diff --git a/Cargo.toml b/Cargo.toml
index 8f6a2af..8814fb3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,6 +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"
[dev-dependencies]
ordered-float = "3.4.0"
diff --git a/src/custom_range_bounds_ord_wrapper.rs b/src/custom_range_bounds_ord_wrapper.rs
deleted file mode 100644
index 2a49743..0000000
--- a/src/custom_range_bounds_ord_wrapper.rs
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-Copyright 2022 James Forster
-
-This file is part of range_bounds_map.
-
-range_bounds_map is free software: you can redistribute it and/or
-modify it under the terms of the GNU Affero General Public License as
-published by the Free Software Foundation, either version 3 of the
-License, or (at your option) any later version.
-
-range_bounds_map is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Affero General Public License for more details.
-
-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::Debug;
-use std::marker::PhantomData;
-use std::ops::RangeBounds;
-
-use crate::bound_ord::BoundOrd;
-
-#[derive(Clone)]
-pub struct BoundOrdBodge {
- bound_ord: BoundOrd
-}
-
-impl OrdBodge for BoundOrdBodge {
- fn cmp(&self, other: &K) -> Ordering {
- Ordering::Less
- }
-}
-
-pub trait OrdBodge {
- fn cmp(&self, other: &K) -> Ordering;
-}
-
-pub enum CustomRangeBoundsOrdWrapper {
- RangeBounds(K),
- OrdBodge(Box>),
- PhantomData(PhantomData)
-}
-
-impl CustomRangeBoundsOrdWrapper {
- //todo rename these after finished
- //re-enable warnings
- //do clippy
- //check doctests
- pub fn rxr(&self) -> &K {
- match self {
- CustomRangeBoundsOrdWrapper::RangeBounds(range_bounds) => {
- return range_bounds;
- }
- _ => panic!("unwrap failed"),
- }
- }
-
- pub fn rx(self) -> K {
- match self {
- CustomRangeBoundsOrdWrapper::RangeBounds(range_bounds) => {
- return range_bounds;
- }
- _ => panic!("unwrap failed"),
- }
- }
-}
-
-impl Ord for CustomRangeBoundsOrdWrapper
-where
- I: Ord,
- K: RangeBounds,
-{
- fn cmp(&self, other: &Self) -> Ordering {
- todo!()
- }
-}
-
-impl PartialOrd for CustomRangeBoundsOrdWrapper
-where
- I: Ord,
- K: RangeBounds,
-{
- fn partial_cmp(&self, other: &Self) -> Option {
- Some(self.cmp(other))
- }
-}
-
-impl Eq for CustomRangeBoundsOrdWrapper
-where
- I: Ord,
- K: RangeBounds,
-{
-}
-
-impl PartialEq for CustomRangeBoundsOrdWrapper
-where
- I: Ord,
- K: RangeBounds,
-{
- fn eq(&self, other: &Self) -> bool {
- self.cmp(other).is_eq()
- }
-}
diff --git a/src/lib.rs b/src/lib.rs
index 7d823d2..ceed3bf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -228,7 +228,6 @@ along with range_bounds_map. If not, see .
#![allow(unused_imports)]
#![allow(unused_variables)]
pub(crate) mod bound_ord;
-pub(crate) mod custom_range_bounds_ord_wrapper;
pub(crate) mod helpers;
pub mod range_bounds_map;
diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs
index b50cef7..b52678c 100644
--- a/src/range_bounds_map.rs
+++ b/src/range_bounds_map.rs
@@ -17,13 +17,13 @@ You should have received a copy of the GNU Affero General Public License
along with range_bounds_map. If not, see .
*/
-use std::collections::btree_map::IntoIter as IntoIterBTreeMap;
-use std::collections::BTreeMap;
use std::fmt::{self, Debug};
use std::iter::once;
use std::marker::PhantomData;
use std::ops::{Bound, RangeBounds};
+use btree_monstousity::BTreeMap;
+use btree_monstousity::btree_map::SearchBoundCustom;
use itertools::Itertools;
use labels::{parent_tested, tested, trivial};
use serde::de::{MapAccess, Visitor};
@@ -31,9 +31,6 @@ use serde::ser::SerializeMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::bound_ord::BoundOrd;
-use crate::custom_range_bounds_ord_wrapper::{
- BoundOrdBodge, CustomRangeBoundsOrdWrapper,
-};
use crate::helpers::is_valid_range_bounds;
use crate::TryFromBounds;
@@ -130,7 +127,8 @@ use crate::TryFromBounds;
/// [`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html
/// [`BTreeMap`]: https://doc.rust-lang.org/std/collections/struct.BTreeMap.html
pub struct RangeBoundsMap {
- inner: BTreeMap, V>,
+ inner: BTreeMap,
+ phantom: PhantomData,
}
/// An error type to represent a [`RangeBounds`] overlapping another
@@ -273,7 +271,7 @@ pub enum OverlapOrTryFromBoundsError {
impl RangeBoundsMap
where
- I: Ord + Clone,
+ I: Ord,
K: RangeBounds,
{
/// Makes a new, empty `RangeBoundsMap`.
@@ -291,6 +289,7 @@ where
pub fn new() -> Self {
RangeBoundsMap {
inner: BTreeMap::new(),
+ phantom: PhantomData,
}
}
@@ -427,38 +426,24 @@ where
pub fn overlapping(
&self,
range_bounds: Q,
- ) -> (
- Bound,
- Bound,
- impl DoubleEndedIterator- ,
- )
+ ) -> impl DoubleEndedIterator
-
where
Q: RangeBounds,
{
- let start_bound = range_bounds.start_bound().cloned();
+ let lower_comp = |inner_range_bounds: &K| {
+ BoundOrd::start(range_bounds.start_bound())
+ .cmp(&BoundOrd::start(inner_range_bounds.start_bound()))
+ };
+ let upper_comp = |inner_range_bounds: &K| {
+ BoundOrd::start(range_bounds.start_bound())
+ .cmp(&BoundOrd::start(inner_range_bounds.start_bound()))
+ };
- let end_bound = range_bounds.end_bound().cloned();
+ let lower_bound = SearchBoundCustom::Included;
+ let upper_bound = SearchBoundCustom::Included;
- let start_bodge = Box::new(BoundOrdBodge {
- bound_ord: BoundOrd::start(start_bound),
- });
- let end_bodge = Box::new(BoundOrdBodge {
- bound_ord: BoundOrd::start(end_bound),
- });
-
- let result = self
- .inner
- .range((
- Bound::Included(CustomRangeBoundsOrdWrapper::OrdBodge(
- start_bodge.clone(),
- )),
- Bound::Included(CustomRangeBoundsOrdWrapper::OrdBodge(
- end_bodge.clone(),
- )),
- ))
- .map(move |(key, value)| (key.rxr(), value));
-
- return (start_bound, end_bound, result);
+ self.inner
+ .range(lower_comp, lower_bound, upper_comp, upper_bound)
}
/// Returns a reference to the `Value` corresponding to the