package fmtsort
Import Path
golang.org/x/exp/collection/internal/fmtsort (on go.dev)
Dependency Relation
imports 3 packages, and imported by one package
Involved Source Files
Package fmtsort provides a general stable ordering mechanism
for maps, on behalf of the fmt and text/template packages.
It is not guaranteed to be efficient and works only for types
that are valid map keys.
Package-Level Type Names (total 2, both are exported)
Package-Level Functions (total 3, in which 2 are exported)
Compare compares two values of the same type. It returns -1, 0, 1
according to whether a > b (1), a == b (0), or a < b (-1).
If the types differ, it returns -1.
See the comment on Sort for the comparison rules.
Sort accepts a map and returns a SortedMap that has the same keys and
values but in a stable sorted order according to the keys, modulo issues
raised by unorderable key values such as NaNs.
The ordering rules are more general than with Go's < operator:
- when applicable, nil compares low
- ints, floats, and strings order by <
- NaN compares less than non-NaN floats
- bool compares false before true
- complex compares real, then imag
- pointers compare by machine address
- channel values compare by machine address
- structs compare each field in turn
- arrays compare each element in turn.
Otherwise identical arrays compare by length.
- interface values compare first by reflect.Type describing the concrete type
and then by concrete value as described in the previous rules.
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)