Skip to content

Commit

Permalink
use the symmetry of set functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 authored and konstin committed Mar 13, 2024
1 parent 0e1d596 commit 10ab631
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ impl<VS: VersionSet> Term<VS> {
pub(crate) fn intersection(&self, other: &Self) -> Self {
match (self, other) {
(Self::Positive(r1), Self::Positive(r2)) => Self::Positive(r1.intersection(r2)),
(Self::Positive(r1), Self::Negative(r2)) => {
Self::Positive(r1.intersection(&r2.complement()))
}
(Self::Negative(r1), Self::Positive(r2)) => {
Self::Positive(r1.complement().intersection(r2))
(Self::Positive(p), Self::Negative(n)) | (Self::Negative(n), Self::Positive(p)) => {
Self::Positive(n.complement().intersection(p))
}
(Self::Negative(r1), Self::Negative(r2)) => Self::Negative(r1.union(r2)),
}
Expand All @@ -115,9 +112,9 @@ impl<VS: VersionSet> Term<VS> {
(Self::Negative(r1), Self::Negative(r2)) => r1 == &VS::empty() && r2 == &VS::empty(),
// If the positive term is a subset of the negative term, it lies fully in the region that the negative
// term excludes.
(Self::Positive(r1), Self::Negative(r2)) => r1.subset_of(r2),
// Inversely, if there is a region outside the negative, they overlap in this region.
(Self::Negative(r1), Self::Positive(r2)) => r2.subset_of(r1),
(Self::Positive(p), Self::Negative(n)) | (Self::Negative(n), Self::Positive(p)) => {
p.subset_of(n)
}
}
}

Expand All @@ -126,11 +123,8 @@ impl<VS: VersionSet> Term<VS> {
pub(crate) fn union(&self, other: &Self) -> Self {
match (self, other) {
(Self::Positive(r1), Self::Positive(r2)) => Self::Positive(r1.union(r2)),
(Self::Positive(r1), Self::Negative(r2)) => {
Self::Negative(r1.complement().intersection(r2))
}
(Self::Negative(r1), Self::Positive(r2)) => {
Self::Negative(r1.intersection(&r2.complement()))
(Self::Positive(p), Self::Negative(n)) | (Self::Negative(n), Self::Positive(p)) => {
Self::Negative(p.complement().intersection(n))
}
(Self::Negative(r1), Self::Negative(r2)) => Self::Negative(r1.intersection(r2)),
}
Expand Down

0 comments on commit 10ab631

Please sign in to comment.