tisonkun commented on code in PR #44: URL: https://github.com/apache/datasketches-rust/pull/44#discussion_r2652065668
########## datasketches/src/frequencies/sketch.rs: ########## @@ -0,0 +1,408 @@ +// 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. + +//! Frequent items sketch implementations. + +use std::hash::Hash; + +use crate::error::SerdeError; +use crate::frequencies::reverse_purge_item_hash_map::ReversePurgeItemHashMap; +use crate::frequencies::serde::ItemsSerde; +use crate::frequencies::serialization::*; + +const LG_MIN_MAP_SIZE: u8 = 3; +const SAMPLE_SIZE: usize = 1024; +const EPSILON_FACTOR: f64 = 3.5; +const LOAD_FACTOR_NUMERATOR: usize = 3; +const LOAD_FACTOR_DENOMINATOR: usize = 4; + +/// Error guarantees for frequent item queries. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ErrorType { + /// Include items if upper bound exceeds threshold (no false negatives). + NoFalseNegatives, + /// Include items if lower bound exceeds threshold (no false positives). + NoFalsePositives, +} + +/// Result row for frequent item queries. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Row<T> { + item: T, + estimate: i64, + upper_bound: i64, + lower_bound: i64, +} + +impl<T> Row<T> { + /// Returns the item value. + pub fn item(&self) -> &T { + &self.item + } + + /// Returns the estimated frequency. + pub fn estimate(&self) -> i64 { + self.estimate + } + + /// Returns the upper bound for the frequency. + pub fn upper_bound(&self) -> i64 { + self.upper_bound + } + + /// Returns the lower bound for the frequency. + pub fn lower_bound(&self) -> i64 { + self.lower_bound + } +} Review Comment: ```java /** * Gets the guaranteed lower bound frequency of the given item, which can never be * negative. * * @param item the given item. * @return the guaranteed lower bound frequency of the given item. That is, a number which * is guaranteed to be no larger than the real frequency. */ public long getLowerBound(final T item) { //LB = itemCount or 0 return hashMap.get(item); } ``` This should be able to use `u64`. See https://github.com/apache/datasketches-cpp/blob/master/fi/include/reverse_purge_hash_map_impl.hpp Please try to update other method docs from Java impls - https://github.com/apache/datasketches-java/blob/main/src/main/java/org/apache/datasketches/frequencies/FrequentItemsSketch.java -- 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]
