Skip to main content

apache_datasketches/tuple/
input.rs

1use super::{ArrayOfDoublesSketch, CompactArrayOfDoublesSketch};
2use apache_datasketches_sys::array_of_doubles_input::ArrayOfDoublesInputRef;
3
4mod sealed {
5    pub trait Sealed {}
6    impl Sealed for super::ArrayOfDoublesSketch {}
7    impl Sealed for super::CompactArrayOfDoublesSketch {}
8}
9
10/// Either ArrayOfDoubles sketch type can be fed into any of this module's set
11/// operations — union, intersection, a-not-b, and Jaccard similarity. This
12/// trait is sealed — it cannot be implemented outside this crate — since the
13/// set-op shims only have concrete overloads for these two exact types.
14pub trait ArrayOfDoublesInput: sealed::Sealed {
15    #[doc(hidden)]
16    fn as_input(&self) -> ArrayOfDoublesInputRef<'_>;
17
18    /// The fixed number of `f64` values each of this sketch's retained
19    /// entries carries. Set operations require all operands to agree.
20    fn get_num_values(&self) -> u8;
21}
22
23impl ArrayOfDoublesInput for ArrayOfDoublesSketch {
24    fn as_input(&self) -> ArrayOfDoublesInputRef<'_> {
25        ArrayOfDoublesInputRef::Sketch(&self.inner)
26    }
27
28    fn get_num_values(&self) -> u8 {
29        ArrayOfDoublesSketch::get_num_values(self)
30    }
31}
32
33impl ArrayOfDoublesInput for CompactArrayOfDoublesSketch {
34    fn as_input(&self) -> ArrayOfDoublesInputRef<'_> {
35        ArrayOfDoublesInputRef::Compact(&self.inner)
36    }
37
38    fn get_num_values(&self) -> u8 {
39        CompactArrayOfDoublesSketch::get_num_values(self)
40    }
41}