tisonkun commented on code in PR #62: URL: https://github.com/apache/datasketches-rust/pull/62#discussion_r2701213070
########## datasketches/src/density/sketch.rs: ########## @@ -0,0 +1,551 @@ +// 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. + +use std::cell::Cell; +use std::io::Read; +use std::io::Write; +use std::time::SystemTime; +use std::time::UNIX_EPOCH; + +use crate::codec::SketchBytes; +use crate::codec::SketchSlice; +use crate::density::serialization::DENSITY_FAMILY_ID; +use crate::density::serialization::FLAGS_IS_EMPTY; +use crate::density::serialization::PREAMBLE_INTS_LONG; +use crate::density::serialization::PREAMBLE_INTS_SHORT; +use crate::density::serialization::SERIAL_VERSION; +use crate::error::Error; +use crate::error::ErrorKind; + +/// Floating point types supported by the density sketch. +pub trait DensityValue: Copy + PartialOrd + 'static { + /// Converts from f64. + fn from_f64(value: f64) -> Self; + /// Converts to f64 for accumulation. + fn to_f64(self) -> f64; +} + +impl DensityValue for f64 { + fn from_f64(value: f64) -> Self { + value + } + + fn to_f64(self) -> f64 { + self + } +} + +impl DensityValue for f32 { + fn from_f64(value: f64) -> Self { + value as f32 + } + + fn to_f64(self) -> f64 { + self as f64 + } +} + +/// Kernel used to compute density contributions between points. +pub trait DensityKernel<T: DensityValue> { + /// Returns the kernel evaluation for the two points. + fn evaluate(&self, left: &[T], right: &[T]) -> T; +} Review Comment: ```suggestion pub trait DensityKernel { /// Returns the kernel evaluation for the two points. fn evaluate<T: DensityValue>(&self, left: &[T], right: &[T]) -> T; } ``` The trait bound doesn't seem to be related to `DensityValue` but it should accept any `DensityValue`. -- 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]
