polars_compute::unique

Trait RangedUniqueKernel

Source
pub trait RangedUniqueKernel {
    type Array: Array;

    // Required methods
    fn has_seen_all(&self) -> bool;
    fn append(&mut self, array: &Self::Array);
    fn finalize_unique(self) -> Self::Array;
    fn finalize_n_unique(self) -> usize;
    fn finalize_n_unique_non_null(self) -> usize;
}
Expand description

Optimized kernel to calculate the unique elements of an array.

This kernel is a specialized for where all values are known to be in some small range of values. In this case, you can usually get by with a bitset and bit-arithmetic instead of using vectors and hashsets. Consequently, this kernel is usually called when further information is known about the underlying array.

This trait is not implemented directly on the Array as with many other kernels. Rather, it is implemented on a State struct to which Arrays can be appended. This allows for sharing of State between many chunks and allows for different implementations for the same array (e.g. a maintain order and no maintain-order variant).

Required Associated Types§

Required Methods§

Source

fn has_seen_all(&self) -> bool

Returns whether all the values in the whole range are in the state

Source

fn append(&mut self, array: &Self::Array)

Append an Array’s values to the State

Source

fn finalize_unique(self) -> Self::Array

Consume the state to get the unique elements

Source

fn finalize_n_unique(self) -> usize

Consume the state to get the number of unique elements including null

Source

fn finalize_n_unique_non_null(self) -> usize

Consume the state to get the number of unique elements excluding null

Implementors§