Comparing v0.1.0

Source
Ready-made ordering callbacks for the key types a tree map or set is keyed on.

CompareUint

pub func CompareUint(left: uint, right: uint) -> Ordering

The ordering of two uint values. Both are read by value. Cannot fail; runs in constant time and allocates nothing.

Source

Parameters

NameTypeDescription
leftuintone of the two values
rightuintthe other

Returns: how left orders against right

CompareUint64

pub func CompareUint64(
    left: uint64,
    right: uint64
) -> Ordering

The ordering of two uint64 values.

Source

Parameters

NameTypeDescription
leftuint64one of the two values
rightuint64the other

Returns: how left orders against right

CompareUint32

pub func CompareUint32(
    left: uint32,
    right: uint32
) -> Ordering

The ordering of two uint32 values.

Source

Parameters

NameTypeDescription
leftuint32one of the two values
rightuint32the other

Returns: how left orders against right

CompareInt64

pub func CompareInt64(left: int64, right: int64) -> Ordering

The ordering of two int64 values. Signed, so this is not the unsigned comparison of the same bits: a negative key sorts below every positive one.

Source

Parameters

NameTypeDescription
leftint64one of the two values
rightint64the other

Returns: how left orders against right

CompareInt32

pub func CompareInt32(left: int32, right: int32) -> Ordering

The ordering of two int32 values.

Source

Parameters

NameTypeDescription
leftint32one of the two values
rightint32the other

Returns: how left orders against right

CompareChar8

pub func CompareChar8(left: char8, right: char8) -> Ordering

The ordering of two char8 code units. By code unit, which for ASCII is alphabetical and for anything above it is UTF-8 byte order — which is the order of the code points, since UTF-8 is ordered that way by construction.

Source

Parameters

NameTypeDescription
leftchar8one of the two values
rightchar8the other

Returns: how left orders against right

CompareSlice

pub func CompareSlice(
    left: char8[..],
    right: char8[..]
) -> Ordering

The ordering of two runs of characters, shortest-first where one is a prefix of the other. Both are borrowed and read. Compares code unit by code unit and, where every shared position agrees, orders the shorter one first — which is the ordering a dictionary uses, and the one Rux/Algorithms sorts by. Cannot fail. Runs in time proportional to the shorter length and allocates nothing.

Source

Parameters

NameTypeDescription
leftchar8[..]one of the two values
rightchar8[..]the other

Returns: how the two order byte by byte, then by length