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)
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. The comparator chosen for a node is:
|
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.
|
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.
|
Returns:
A sorter(node) function that always returns the same tuple.
- Type
- function
Example
const sorter = SORTER.UNIFORM(ORDER.ASCENDING, false);