packages

table::sort

On this page

Sorting: every key becomes an order-preserving u64 per row (numbers by their bits, strings by rank among the distinct values), then a stable LSD radix sort of (key, row) pairs, last key first. O(n) per key; 11-bit digits, constant digits skipped. Above PAR_ROWS rows the keys are encoded and the radix passes run on several workers.

Structs

SortKeySource

pub struct SortKey

One sort key: a column, its direction and where nulls go.

nabi
use table::{asc, desc};
let t = table::table!{ "g": ["b", "a", "b"], "x": [1, 2, 3] };
let s = try t.sort([asc("g"), desc("x")]) catch _ { t };
assert(s.column_at(1).to_options_i64() == [2, 3, 1]);
  • pub name: str§

    Source
  • pub descending: bool§

    Source
  • pub nulls_last: bool§

    Source
  • pub fn nulls_first(self) -> SortKey§

    Source

    Nulls before every value.

  • pub fn nulls_last(self) -> SortKey§

    Source

    Nulls after every value.

Functions

ascSource

pub fn asc(name: str) -> SortKey

Ascending by name, nulls last.

descSource

pub fn desc(name: str) -> SortKey

Descending by name, nulls last.

Implementations

impl Table

  • pub fn argsort(self, keys: List<SortKey>) throws (TableError) -> List<usize>§

    Source

    The row order that sorts by keys (stable: ties keep their order), without moving any data.

  • pub fn sort(self, keys: List<SortKey>) throws (TableError) -> Table§

    Source

    The rows ordered by keys (stable, multi-key; each key ascending or descending with nulls first or last). Strings sort by code point, floats with NaN after every number.

    nabi
    use table::desc;
    let t = table::table!{ "x": [2.0, none, 3.0, 1.0] };
    let s = try t.sort([desc("x").nulls_first()]) catch _ { t };
    assert(s.column_at(0).to_options_f64() == [none, 3.0, 2.0, 1.0]);
    
  • pub fn sort_by(self, names: List<str>) throws (TableError) -> Table§

    Source

    Ascending by the columns names.