Skip to main content

Module compare

Module compare 

Source

Functions§

compare_dictionary
compare_general_numeric
General numeric sort (-g): handles scientific notation, infinity, NaN. O(n) parser.
compare_human_numeric
Human numeric sort (-h): handles suffixes K, M, G, T, P, E, Z, Y.
compare_ignore_case
compare_ignore_nonprinting
compare_lexical
Compare two byte slices lexicographically (default sort).
compare_month
Month sort (-M).
compare_numeric
Numeric sort (-n): compare leading numeric strings. Handles optional leading whitespace, sign, and decimal point.
compare_random
Random sort (-R): hash-based shuffle that groups identical keys.
compare_version
Version sort (-V): natural sort of version numbers. Uses byte slices directly instead of char iterators for maximum performance.
compare_with_opts
Master comparison function that dispatches based on KeyOpts.
int_to_sortable_u64
Convert an i64 to a sortable u64 whose natural ordering matches signed integer ordering. Adds i64::MAX + 1 (0x8000000000000000) to shift the range to unsigned.
parse_general_numeric
parse_human_numeric
parse_numeric_value
Fast custom numeric parser: parses sign + digits + optional decimal directly from bytes. Avoids UTF-8 validation and str::parse::() overhead entirely. Uses batch digit processing for the integer part (4 digits at a time) to reduce loop iterations and branch mispredictions.
select_comparator
Select a concrete comparison function based on KeyOpts. Returns (compare_fn, needs_leading_blank_strip, needs_reverse). The caller applies blank-stripping and reversal outside the function pointer, eliminating all per-comparison branching.
skip_leading_blanks
Strip leading blanks (space and tab).
try_parse_integer
Fast integer-only parser for numeric sort (-n). Returns Some(i64) if the value is a pure integer (no decimal point, no exponent). Returns None if the value has a decimal point or is not a valid integer. This avoids the f64 conversion path for integer-only data. Uses wrapping arithmetic (no overflow checks) for speed — values >18 digits may wrap but sort order is still consistent since all values wrap the same way.

Type Aliases§

CompareFn
Concrete comparison function type. Selected once at setup time to avoid per-comparison flag checking in hot sort loops.