it compiles!
This commit is contained in:
parent
bff57a8c37
commit
032e28866d
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<I> {
|
||||
bound_ord: BoundOrd<I>
|
||||
}
|
||||
|
||||
impl<I, K> OrdBodge<K> for BoundOrdBodge<I> {
|
||||
fn cmp(&self, other: &K) -> Ordering {
|
||||
Ordering::Less
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrdBodge<K> {
|
||||
fn cmp(&self, other: &K) -> Ordering;
|
||||
}
|
||||
|
||||
pub enum CustomRangeBoundsOrdWrapper<I, K> {
|
||||
RangeBounds(K),
|
||||
OrdBodge(Box<dyn OrdBodge<K>>),
|
||||
PhantomData(PhantomData<I>)
|
||||
}
|
||||
|
||||
impl<I, K> CustomRangeBoundsOrdWrapper<I, K> {
|
||||
//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<I, K> Ord for CustomRangeBoundsOrdWrapper<I, K>
|
||||
where
|
||||
I: Ord,
|
||||
K: RangeBounds<I>,
|
||||
{
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, K> PartialOrd for CustomRangeBoundsOrdWrapper<I, K>
|
||||
where
|
||||
I: Ord,
|
||||
K: RangeBounds<I>,
|
||||
{
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, K> Eq for CustomRangeBoundsOrdWrapper<I, K>
|
||||
where
|
||||
I: Ord,
|
||||
K: RangeBounds<I>,
|
||||
{
|
||||
}
|
||||
|
||||
impl<I, K> PartialEq for CustomRangeBoundsOrdWrapper<I, K>
|
||||
where
|
||||
I: Ord,
|
||||
K: RangeBounds<I>,
|
||||
{
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.cmp(other).is_eq()
|
||||
}
|
||||
}
|
@ -228,7 +228,6 @@ along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
|
||||
#![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;
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<I, K, V> {
|
||||
inner: BTreeMap<CustomRangeBoundsOrdWrapper<I, K>, V>,
|
||||
inner: BTreeMap<K, V>,
|
||||
phantom: PhantomData<I>,
|
||||
}
|
||||
|
||||
/// An error type to represent a [`RangeBounds`] overlapping another
|
||||
@ -273,7 +271,7 @@ pub enum OverlapOrTryFromBoundsError {
|
||||
|
||||
impl<I, K, V> RangeBoundsMap<I, K, V>
|
||||
where
|
||||
I: Ord + Clone,
|
||||
I: Ord,
|
||||
K: RangeBounds<I>,
|
||||
{
|
||||
/// 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<Q>(
|
||||
&self,
|
||||
range_bounds: Q,
|
||||
) -> (
|
||||
Bound<I>,
|
||||
Bound<I>,
|
||||
impl DoubleEndedIterator<Item = (&K, &V)>,
|
||||
)
|
||||
) -> impl DoubleEndedIterator<Item = (&K, &V)>
|
||||
where
|
||||
Q: RangeBounds<I>,
|
||||
{
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user