add 2023 to copyright
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2022 James Forster
|
||||
Copyright 2022,2023 James Forster
|
||||
|
||||
This file is part of discrete_range_map.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2022 James Forster
|
||||
Copyright 2022,2023 James Forster
|
||||
|
||||
This file is part of discrete_range_map.
|
||||
|
||||
|
||||
+29
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2022 James Forster
|
||||
Copyright 2022,2023 James Forster
|
||||
|
||||
This file is part of discrete_range_map.
|
||||
|
||||
@@ -18,6 +18,7 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use crate::discrete_range_map::FiniteRange;
|
||||
use crate::DiscreteFinite;
|
||||
|
||||
///both ends are always included
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -26,6 +27,33 @@ pub struct Interval<I> {
|
||||
pub end: I,
|
||||
}
|
||||
|
||||
impl<I> Interval<I>
|
||||
where
|
||||
I: Ord + DiscreteFinite + Copy,
|
||||
{
|
||||
pub fn contains(&self, point: I) -> bool {
|
||||
point >= self.start && point <= self.end
|
||||
}
|
||||
|
||||
///requires that self comes before other and they don't overlap
|
||||
pub fn touches_ordered(&self, other: &Self) -> bool {
|
||||
self.end == other.start.down().unwrap()
|
||||
}
|
||||
|
||||
///requires that self comes before other
|
||||
pub fn overlaps_ordered(&self, other: &Self) -> bool {
|
||||
self.contains(other.start) || self.contains(other.end)
|
||||
}
|
||||
|
||||
///requires that self comes before other
|
||||
pub fn merge_ordered(self, other: &Self) -> Self {
|
||||
Interval {
|
||||
start: self.start,
|
||||
end: other.end,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I> FiniteRange<I> for Interval<I>
|
||||
where
|
||||
I: Copy,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2022 James Forster
|
||||
Copyright 2022,2023 James Forster
|
||||
|
||||
This file is part of discrete_range_map.
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2022 James Forster
|
||||
Copyright 2022,2023 James Forster
|
||||
|
||||
This file is part of discrete_range_map.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user