apache_datasketches/tuple/
a_not_b.rs1use super::input::ArrayOfDoublesInput;
2use super::CompactArrayOfDoublesSketch;
3use crate::error::SketchError;
4use apache_datasketches_sys::array_of_doubles_a_not_b::ffi as sys;
5use apache_datasketches_sys::array_of_doubles_input::ArrayOfDoublesInputRef;
6use cxx::UniquePtr;
7
8pub struct ArrayOfDoublesAnotB {
14 inner: UniquePtr<sys::ArrayOfDoublesAnotBShim>,
15}
16
17unsafe impl Send for ArrayOfDoublesAnotB {}
18
19impl Default for ArrayOfDoublesAnotB {
20 fn default() -> Self {
21 Self::new()
22 }
23}
24
25impl ArrayOfDoublesAnotB {
26 pub fn new() -> Self {
28 Self {
29 inner: sys::new_array_of_doubles_a_not_b(),
30 }
31 }
32
33 pub fn compute(
43 &self,
44 a: &impl ArrayOfDoublesInput,
45 b: &impl ArrayOfDoublesInput,
46 ordered: bool,
47 ) -> Result<CompactArrayOfDoublesSketch, SketchError> {
48 let (a_num, b_num) = (a.get_num_values(), b.get_num_values());
49 if a_num != b_num {
50 return Err(SketchError::InvalidConfig(format!(
51 "num_values mismatch: a has {a_num}, b has {b_num}"
52 )));
53 }
54 let inner = match (a.as_input(), b.as_input()) {
55 (ArrayOfDoublesInputRef::Sketch(a), ArrayOfDoublesInputRef::Sketch(b)) => {
56 self.inner.compute_sketch_sketch(a, b, ordered)
57 }
58 (ArrayOfDoublesInputRef::Sketch(a), ArrayOfDoublesInputRef::Compact(b)) => {
59 self.inner.compute_sketch_compact(a, b, ordered)
60 }
61 (ArrayOfDoublesInputRef::Compact(a), ArrayOfDoublesInputRef::Sketch(b)) => {
62 self.inner.compute_compact_sketch(a, b, ordered)
63 }
64 (ArrayOfDoublesInputRef::Compact(a), ArrayOfDoublesInputRef::Compact(b)) => {
65 self.inner.compute_compact_compact(a, b, ordered)
66 }
67 };
68 Ok(CompactArrayOfDoublesSketch::from_shim(inner))
69 }
70}