Namespace: SORTER

SORTER

Factory functions that create sorter functions.

A sorter(node) function must return a tuple:

sorter(node) → [keyComparator, valueComparatorOrFlag]

This tuple controls how each node computes:

  • sortedKeys — ordering of its child keys
  • sortedValues — ordering of values (its equivalence class)
Source:

Methods

(static) BY_DEPTH(keyComparators, valueComparatorsOrFlags) → {function}

Creates a depth-aware sorter(node) function.

Parameters:
Name Type Description
keyComparators function | Array.<function()>

A key comparator or an array of comparators indexed by depth.
If a single function is provided, it is wrapped into an array.

The comparator chosen for a node is:

  • keyComparators[node.depth] if it exists
  • otherwise the last comparator in the array
valueComparatorsOrFlags function | boolean | Array.<(function()|boolean)>

Comparator(s) or boolean flag(s) controlling ordering of stored values. A single entry is upgraded to an array.

  • comparator → values stored in a SortedArray
  • boolean → values stored in an ArrayQueue
    • false → FIFO
    • true → LIFO
Source:
Returns:

Returns a function that, for each node, selects:

  • the appropriate key comparator based on depth
  • the appropriate value comparator/flag based on depth
Type
function
Example
const sorter = SORTER.BY_DEPTH([ORDER.ASCENDING, ORDER.DESCENDING], true);

(static) UNIFORM(keyComparator, valueComparatorOrFlag) → {function}

Creates a uniform sorter(node) function where all nodes, at any depth, use the same key comparator and the same value comparator/flag.

This is the opposite of SORTER.BY_DEPTH.
Instead of varying by node.depth, the sorting strategy is globally consistent across the entire classifier.

Parameters:
Name Type Description
keyComparator function

Comparator used to order all child keys in every node.

valueComparatorOrFlag function | boolean

Comparator or queue-flag used to order values in all nodes.

  • comparator → values stored in a SortedArray
  • boolean → values stored in an ArrayQueue
    • false → FIFO
    • true → LIFO
Source:
Returns:

A sorter(node) function that always returns the same tuple.

Type
function
Example
const sorter = SORTER.UNIFORM(ORDER.ASCENDING, false);