Skip to content

Commit

Permalink
fix: re-add union and remove early out
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed May 29, 2022
1 parent e72a3f5 commit 71fbe52
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ impl<V: Ord> Range<V> {

/// Returns true if the this Range contains the specified value.
pub fn contains(&self, v: &V) -> bool {
if let Some(bounding_range) = self.bounding_range() {
if !bounding_range.contains(v) {
return false;
}
}

for segment in self.segments.iter() {
if match segment {
(Unbounded, Unbounded) => true,
Expand Down Expand Up @@ -230,6 +224,13 @@ fn bound_as_ref<V>(bound: &Bound<V>) -> Bound<&V> {
}

impl<V: Ord + Clone> Range<V> {
/// Computes the union of this `Range` and another.
pub fn union(&self, other: &Self) -> Self {
self.complement()
.intersection(&other.complement())
.complement()
}

/// Computes the intersection of two sets of versions.
pub fn intersection(&self, other: &Self) -> Self {
let mut segments: SmallVec<Interval<V>> = SmallVec::empty();
Expand Down Expand Up @@ -387,6 +388,10 @@ impl<T: Debug + Display + Clone + Eq + Ord> VersionSet for Range<T> {
fn full() -> Self {
Range::full()
}

fn union(&self, other: &Self) -> Self {
Range::union(self, other)
}
}

// REPORT ######################################################################
Expand Down

0 comments on commit 71fbe52

Please sign in to comment.