package fmtsort
import "internal/fmtsort"
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.
Index ¶
Types ¶
type SortedMap ¶
SortedMap represents a map's keys and values. The keys and values are aligned in index order: Value[i] is the value in the map corresponding to Key[i].
func Sort ¶
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.
func (*SortedMap) Len ¶
func (*SortedMap) Less ¶
func (*SortedMap) Swap ¶
Source Files ¶
- Version
- v1.12.14
- Published
- Dec 4, 2019
- Platform
- darwin/amd64
- Imports
- 2 packages
- Last checked
- 4 minutes ago –
Tools for package owners.