Imports #
"cmp"
"reflect"
"slices"
"cmp"
"reflect"
"slices"
SortedMap is a slice of KeyValue pairs that simplifies sorting and iterating over map entries. Each KeyValue pair contains a map key and its corresponding value.
type SortedMap []KeyValue
KeyValue holds a single key and value pair found in a map.
type KeyValue struct {
Key reflect.Value
Value reflect.Value
}
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 Sort(mapValue reflect.Value) SortedMap
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.
func compare(aVal reflect.Value, bVal reflect.Value) int
nilCompare checks whether either value is nil. If not, the boolean is false. If either value is nil, the boolean is true and the integer is the comparison value. The comparison is defined to be 0 if both are nil, otherwise the one nil value compares low. Both arguments must represent a chan, func, interface, map, pointer, or slice.
func nilCompare(aVal reflect.Value, bVal reflect.Value) (int, bool)
Generated with Arrow