diff --git a/fastcrypto/src/hash.rs b/fastcrypto/src/hash.rs index 8df0448ece..01f90d9e98 100644 --- a/fastcrypto/src/hash.rs +++ b/fastcrypto/src/hash.rs @@ -234,6 +234,9 @@ pub trait MultisetHash: Eq { /// Add all the elements of another hash function into this hash function. fn union(&mut self, other: &Self); + /// Remove all the elements of another hash function from this hash function. + fn subtract(&mut self, other: &Self); + // Note that the "remove" operation is safe even if an item has been removed // more times than it has been inserted. To see why, consider the following // example: Suppose an adversary has performed two sets of "insert(x)" and @@ -302,6 +305,10 @@ impl MultisetHash<32> for EllipticCurveMultisetHash { self.accumulator += other.accumulator; } + fn subtract(&mut self, other: &Self) { + self.accumulator -= other.accumulator; + } + fn remove>(&mut self, item: Data) { self.accumulator -= Self::hash_to_point(item); }