From 10adccbdb879d2f31901ca10b060ca1d6fac58f5 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 7 Jun 2023 22:33:10 -0700 Subject: [PATCH] Add subtract to MultiHash --- fastcrypto/src/hash.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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); }