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

type SortedMap struct {
	Key   []reflect.Value
	Value []reflect.Value
}

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

func Sort(mapValue reflect.Value) *SortedMap

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:

func (*SortedMap) Len

func (o *SortedMap) Len() int

func (*SortedMap) Less

func (o *SortedMap) Less(i, j int) bool

func (*SortedMap) Swap

func (o *SortedMap) Swap(i, j int)