that's me done for today I think, nearly flipping back to regular sleep patterns like the ship in pirates of the carribean lol
This commit is contained in:
@@ -4,7 +4,7 @@ use std::ops::{Bound, RangeBounds};
|
||||
|
||||
use derive_new::new;
|
||||
|
||||
use crate::bound_ext::{EndBoundWithOrd, StartBoundWithOrd};
|
||||
use crate::specific_bounds::{EndBound, StartBound};
|
||||
|
||||
type Id = u128;
|
||||
|
||||
@@ -14,9 +14,9 @@ pub struct RangeBoundsSet<T, I> {
|
||||
#[new(default)]
|
||||
ranges: HashMap<Id, T>,
|
||||
#[new(default)]
|
||||
starts: BTreeSet<StartBoundWithOrd<I>>,
|
||||
starts: BTreeSet<StartBound<I>>,
|
||||
#[new(default)]
|
||||
ends: BTreeSet<EndBoundWithOrd<I>>,
|
||||
ends: BTreeSet<EndBound<I>>,
|
||||
phantom_data: PhantomData<I>,
|
||||
|
||||
#[new(default)]
|
||||
@@ -26,7 +26,7 @@ pub struct RangeBoundsSet<T, I> {
|
||||
impl<T, I> RangeBoundsSet<T, I>
|
||||
where
|
||||
T: RangeBounds<I>,
|
||||
I: Ord,
|
||||
I: Ord + Clone,
|
||||
{
|
||||
//returns Err(()) if the inserting the given range overlaps another range
|
||||
//coalesces ranges if they touch
|
||||
@@ -37,7 +37,11 @@ where
|
||||
pub fn raw_insert(&mut self, range: T) {}
|
||||
|
||||
pub fn overlapping(&self, range: T) {
|
||||
self.ends.range(range);
|
||||
let end_bounds_range = (
|
||||
EndBound::from(range.start_bound().cloned()),
|
||||
EndBound::from(range.end_bound().cloned()),
|
||||
);
|
||||
self.ends.range(end_bounds_range);
|
||||
}
|
||||
|
||||
pub fn get(&self, point: &I) {}
|
||||
@@ -66,4 +70,17 @@ mod tests {
|
||||
// script to streamline the manual input process. The script
|
||||
// essentially enumerates all of the generated cases and asks me
|
||||
// to input the expected
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// Rusts Bounds types are overly ambiguous in RangeBouns, it
|
||||
// should return StartBound and EndBound so that you can
|
||||
// implement Ord on them
|
||||
}
|
||||
|
||||
@@ -1,57 +1,8 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::ops::{Bound, RangeBounds};
|
||||
|
||||
use crate::bound_ext::BoundExt;
|
||||
|
||||
pub enum StartBound<T> {
|
||||
Included(T),
|
||||
Excluded(T),
|
||||
Unbounded,
|
||||
}
|
||||
|
||||
impl<T> PartialEq for StartBound<T>
|
||||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self.inner(), other.inner()) {
|
||||
(Some(start1), Some(start2)) => start1 == start2,
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialOrd for StartBound<T>
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
match (self.inner(), other.inner()) {
|
||||
(Some(start1), Some(start2)) => start1.partial_cmp(start2),
|
||||
(None, Some(_)) => Some(Ordering::Less),
|
||||
(Some(_), None) => Some(Ordering::Greater),
|
||||
(None, None) => Some(Ordering::Equal),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> BoundExt<T> for StartBound<T> {
|
||||
fn inner(&self) -> Option<&T> {
|
||||
match self {
|
||||
StartBound::Included(inner) => Some(inner),
|
||||
StartBound::Excluded(inner) => Some(inner),
|
||||
StartBound::Unbounded => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_unbounded(&self) -> bool {
|
||||
match self {
|
||||
StartBound::Unbounded => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum EndBound<T> {
|
||||
Included(T),
|
||||
Excluded(T),
|
||||
@@ -71,12 +22,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for EndBound<T> where T: PartialEq {}
|
||||
|
||||
impl<T> PartialOrd for EndBound<T>
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
match (self.inner(), other.inner()) {
|
||||
//todo fix meh
|
||||
(Some(start1), Some(start2)) => start1.partial_cmp(start2),
|
||||
(None, Some(_)) => Some(Ordering::Less),
|
||||
(Some(_), None) => Some(Ordering::Greater),
|
||||
@@ -85,6 +39,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Ord for EndBound<T>
|
||||
where
|
||||
T: PartialOrd,
|
||||
{
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> RangeBounds<EndBound<T>> for (EndBound<T>, EndBound<T>) {
|
||||
fn start_bound(&self) -> Bound<&EndBound<T>> {
|
||||
self.0
|
||||
}
|
||||
fn end_bound(&self) -> Bound<&EndBound<T>> {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> BoundExt<T> for EndBound<T> {
|
||||
fn inner(&self) -> Option<&T> {
|
||||
match self {
|
||||
@@ -101,3 +73,13 @@ impl<T> BoundExt<T> for EndBound<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Bound<T>> for EndBound<T> {
|
||||
fn from(value: Bound<T>) -> Self {
|
||||
match value {
|
||||
Bound::Included(item) => EndBound::Included(item),
|
||||
Bound::Excluded(item) => EndBound::Excluded(item),
|
||||
Bound::Unbounded => Self::Unbounded,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user