diff --git a/src/discrete_finite.rs b/src/discrete_finite.rs
index aee31db..309be75 100644
--- a/src/discrete_finite.rs
+++ b/src/discrete_finite.rs
@@ -1,5 +1,5 @@
/*
-Copyright 2022 James Forster
+Copyright 2022,2023 James Forster
This file is part of discrete_range_map.
diff --git a/src/discrete_range_map.rs b/src/discrete_range_map.rs
index cc63726..044ad19 100644
--- a/src/discrete_range_map.rs
+++ b/src/discrete_range_map.rs
@@ -1,5 +1,5 @@
/*
-Copyright 2022 James Forster
+Copyright 2022,2023 James Forster
This file is part of discrete_range_map.
diff --git a/src/interval.rs b/src/interval.rs
index f17b197..6b91bbf 100644
--- a/src/interval.rs
+++ b/src/interval.rs
@@ -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 .
*/
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 {
pub end: I,
}
+impl Interval
+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 FiniteRange for Interval
where
I: Copy,
diff --git a/src/lib.rs b/src/lib.rs
index 12883b4..4c735f7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
/*
-Copyright 2022 James Forster
+Copyright 2022,2023 James Forster
This file is part of discrete_range_map.
diff --git a/src/utils.rs b/src/utils.rs
index f7f5b78..b1d8f6e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,5 +1,5 @@
/*
-Copyright 2022 James Forster
+Copyright 2022,2023 James Forster
This file is part of discrete_range_map.