From 10ab631a65c26ad8701065d2aacfd62744b73c3b Mon Sep 17 00:00:00 2001
From: Jacob Finkelman <jfinkelm@amazon.com>
Date: Wed, 13 Mar 2024 16:00:56 +0000
Subject: [PATCH] use the symmetry of set functions

---
 src/term.rs | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/term.rs b/src/term.rs
index 4478192b..0081933c 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -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)),
         }
@@ -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)
+            }
         }
     }
 
@@ -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)),
         }