ZENOTME commented on code in PR #155: URL: https://github.com/apache/datasketches-rust/pull/155#discussion_r3649338385
########## datasketches/src/tuple/a_not_b.rs: ########## @@ -0,0 +1,472 @@ +// 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 set difference (`A and not B`). +//! +//! [`TupleAnotB`] computes the set difference of two Tuple sketches: the keys retained in `A` that +//! are not present in `B`. Surviving keys keep their summaries from `A` unchanged, so unlike the +//! union and intersection this operation needs no combine policy. + +use std::collections::HashSet; + +use crate::error::Error; +use crate::hash::DEFAULT_UPDATE_SEED; +use crate::hash::compute_seed_hash; +use crate::thetacommon::constants::MAX_THETA; +use crate::tuple::hash_table::TupleEntry; +use crate::tuple::sketch::CompactTupleSketch; +use crate::tuple::sketch::TupleSketchView; + +/// Set difference operator (`A and not B`) for Tuple sketches. +/// +/// This is a stateless operator (other than the seed): each call to [`compute`](Self::compute) +/// takes two input sketches and returns a new [`CompactTupleSketch`]. Surviving keys carry their +/// summaries straight from `A`. +/// +/// # Examples +/// +/// ``` +/// # use datasketches::tuple::{DefaultUpdatePolicy, TupleAnotB, TupleSketchBuilder}; +/// let update_policy = DefaultUpdatePolicy::<u64>::default(); +/// let mut a = TupleSketchBuilder::new(update_policy).build(); +/// a.update("apple", 1); +/// a.update("banana", 1); +/// +/// let mut b = TupleSketchBuilder::new(update_policy).build(); +/// b.update("banana", 1); +/// +/// let a_not_b = TupleAnotB::new_with_default_seed(); +/// let result = a_not_b.compute(&a, &b, true).unwrap(); +/// assert_eq!(result.num_retained(), 1); // only "apple" survives +/// ``` +#[derive(Debug, Clone, Copy)] +pub struct TupleAnotB { Review Comment: Should we have shared `RawAnotB` in thetacommon? -- 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]
