ariesdevil commented on code in PR #181:
URL: https://github.com/apache/datasketches-rust/pull/181#discussion_r3718403949


##########
datasketches/src/thetafamily/common/jaccard_similarity.rs:
##########
@@ -299,6 +269,71 @@ impl JaccardSimilarityOperator {
             union.theta64(),
         )
     }
+
+    pub(crate) fn exactly_equal<A, B>(&self, sketch_a: &A, sketch_b: &B) -> 
Result<bool, Error>
+    where
+        A: ThetaKeySketchView,
+        B: ThetaKeySketchView,
+    {
+        if sketch_a.is_empty() && sketch_b.is_empty() {
+            return Ok(true);
+        }
+        if sketch_a.is_empty() || sketch_b.is_empty() {
+            return Ok(false);
+        }
+
+        let union = self.compute_union(sketch_a, sketch_b)?;
+        Ok(identical_sets(sketch_a, sketch_b, &union))
+    }
+
+    fn compute_union<A, B>(
+        &self,
+        sketch_a: &A,
+        sketch_b: &B,
+    ) -> Result<CompactSketchParts<KeyEntry>, Error>
+    where
+        A: ThetaKeySketchView,
+        B: ThetaKeySketchView,
+    {
+        self.validate_seed_hash(sketch_a)?;
+        self.validate_seed_hash(sketch_b)?;
+
+        let sketch_a = KeySketchView::new(sketch_a);
+        let sketch_b = KeySketchView::new(sketch_b);
+        let mut union = UnionState::new(
+            union_lg_k(sketch_a.num_retained(), sketch_b.num_retained()),
+            ResizeFactor::X8,
+            1.0,
+            self.seed,
+            NoopMergePolicy,
+        );
+        union.update(&sketch_a)?;
+        union.update(&sketch_b)?;
+        Ok(union.to_compact_parts(false))
+    }
+
+    fn validate_seed_hash<S: ThetaKeySketchView>(&self, sketch: &S) -> 
Result<(), Error> {
+        let expected = compute_seed_hash(self.seed);
+        if expected != sketch.seed_hash() {
+            return Err(Error::invalid_argument(format!(
+                "incompatible seed hash: expected {}, got {}",
+                expected,
+                sketch.seed_hash(),
+            )));
+        }
+        Ok(())
+    }
+}
+
+fn identical_sets<A, B>(sketch_a: &A, sketch_b: &B, union: 
&CompactSketchParts<KeyEntry>) -> bool

Review Comment:
   Oh, I see the C++ impl uses the same name, so just adding some docs is fine 
for me.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to