use arrow::array::Array;12/// Kernel to calculate the number of unique elements where the elements are already sorted.3pub trait SortedUniqueKernel: Array {4/// Calculate the set of unique elements in `fst` and `others` and fold the result into one5/// array.6fn unique_fold<'a>(fst: &'a Self, others: impl Iterator<Item = &'a Self>) -> Self;78/// Calculate the set of unique elements in [`Self`] where we have no further information about9/// `self`.10fn unique(&self) -> Self;1112/// Calculate the number of unique elements in [`Self`]13///14/// A null is also considered a unique value15fn n_unique(&self) -> usize;1617/// Calculate the number of unique non-null elements in [`Self`]18fn n_unique_non_null(&self) -> usize;19}2021/// Optimized kernel to calculate the unique elements of an array.22///23/// This kernel is a specialized for where all values are known to be in some small range of24/// values. In this case, you can usually get by with a bitset and bit-arithmetic instead of using25/// vectors and hashsets. Consequently, this kernel is usually called when further information is26/// known about the underlying array.27///28/// This trait is not implemented directly on the `Array` as with many other kernels. Rather, it is29/// implemented on a `State` struct to which `Array`s can be appended. This allows for sharing of30/// `State` between many chunks and allows for different implementations for the same array (e.g. a31/// maintain order and no maintain-order variant).32pub trait RangedUniqueKernel {33type Array: Array;3435/// Returns whether all the values in the whole range are in the state36fn has_seen_all(&self) -> bool;3738/// Append an `Array`'s values to the `State`39fn append(&mut self, array: &Self::Array);4041/// Append another state into the `State`42fn append_state(&mut self, other: &Self);4344/// Consume the state to get the unique elements45fn finalize_unique(self) -> Self::Array;46/// Consume the state to get the number of unique elements including null47fn finalize_n_unique(&self) -> usize;48/// Consume the state to get the number of unique elements excluding null49fn finalize_n_unique_non_null(&self) -> usize;50}5152/// A generic unique kernel that selects the generally applicable unique kernel for an `Array`.53pub trait GenericUniqueKernel {54/// Calculate the set of unique elements55fn unique(&self) -> Self;56/// Calculate the number of unique elements including null57fn n_unique(&self) -> usize;58/// Calculate the number of unique elements excluding null59fn n_unique_non_null(&self) -> usize;60}6162mod boolean;63mod dictionary;64mod primitive;6566pub use boolean::BooleanUniqueKernelState;67pub use dictionary::DictionaryRangedUniqueState;68pub use primitive::PrimitiveRangedUniqueState;697071