ZENOTME commented on code in PR #138:
URL: https://github.com/apache/datasketches-rust/pull/138#discussion_r3537407241


##########
datasketches/src/tuple/union.rs:
##########
@@ -0,0 +1,495 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Tuple sketch union.
+//!
+//! [`TupleUnion`] computes the union (set OR) of any number of Tuple 
sketches. Like the Theta union
+//! it keeps an internal "gadget" hash table plus a running `union_theta`, and 
updates it from each
+//! input sketch. The only Tuple-specific behavior is that when an incoming 
key already exists in
+//! the gadget, the two summaries are combined with a [`SummaryCombinePolicy`] 
instead of one being
+//! dropped.
+
+use std::marker::PhantomData;
+
+use crate::common::ResizeFactor;
+use crate::error::Error;
+use crate::hash::DEFAULT_UPDATE_SEED;
+use crate::theta::DEFAULT_LG_K;
+use crate::theta::MAX_LG_K;
+use crate::theta::MIN_LG_K;
+use crate::tuple::hash_table::TupleHashTable;
+use crate::tuple::policy::DefaultUnionPolicy;
+use crate::tuple::policy::SummaryCombinePolicy;
+use crate::tuple::sketch::CompactTupleSketch;
+use crate::tuple::sketch::TupleSketchView;
+
+/// Union (set OR) of Tuple sketches.
+///
+/// `S` is the summary type and `P` is the [`SummaryCombinePolicy`] applied 
when a key is present in
+/// more than one input. For additive summaries the default 
[`DefaultUnionPolicy`] is used.
+///
+/// # Examples
+///
+/// ```
+/// # use datasketches::tuple::{TupleUnion, UpdatableTupleSketch};
+/// let mut a = UpdatableTupleSketch::<u64>::builder().build();
+/// a.update("apple", 1);
+/// a.update("banana", 1);
+///
+/// let mut b = UpdatableTupleSketch::<u64>::builder().build();
+/// b.update("banana", 1);
+/// b.update("cherry", 1);
+///
+/// let mut union = TupleUnion::<u64>::builder().build();
+/// union.update(&a).unwrap();
+/// union.update(&b).unwrap();
+///
+/// let result = union.result(true);
+/// assert_eq!(result.num_retained(), 3); // apple, banana, cherry
+/// ```
+#[derive(Debug)]
+pub struct TupleUnion<S, P = DefaultUnionPolicy> {

Review Comment:
   Yes. I send a implementation : 
https://github.com/apache/datasketches-rust/pull/145 . But it's a intermediate 
state for theta. I think in final we should have something like `ThetaUnion<E, 
P = DefaultUnionPolicy>` (or `RawThetaUnion<E, P = DefaultUnionPolicy>`) so 
that tuple union and theta union can reuse it in both.
   
   In https://github.com/apache/datasketches-rust/pull/145 I didn't implement 
it in this way is because we need to have RawHashTable first. 🤣



-- 
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