go2hx

manual

github

Module: stdgo.internal.fmtsort

(view library index)

Overview

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

Functions

import stdgo.internal.fmtsort.Fmtsort

function _compare

function _compare(_aVal:stdgo.reflect.Value, _bVal:stdgo.reflect.Value):stdgo.GoInt

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.

(view code)

function _floatCompare

function _floatCompare(_a:stdgo.GoFloat64, _b:stdgo.GoFloat64):stdgo.GoInt

floatCompare compares two floating-point values. NaNs compare low.

(view code)

function _isNaN

function _isNaN(_a:stdgo.GoFloat64):Bool

(view code)

function _nilCompare

function _nilCompare(_aVal:stdgo.reflect.Value, _bVal:stdgo.reflect.Value):{
	_1:Bool;
	_0:stdgo.GoInt;
}

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.

(view code)

function compare

function compare(_a:stdgo.reflect.Value, _b:stdgo.reflect.Value):stdgo.GoInt

(view code)

function sort

function sort(_mapValue:stdgo.reflect.Value):stdgo.Ref<stdgo.internal.fmtsort.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:

   - 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.

(view code)

Classes

import stdgo.internal.fmtsort.*

class 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].

var key:stdgo.Slice<stdgo.reflect.Value>
var value:stdgo.Slice<stdgo.reflect.Value>

SortedMap function new

function new(?key:stdgo.Slice<stdgo.reflect.Value>, ?value:stdgo.Slice<stdgo.reflect.Value>):Void

(view code)

SortedMap function len

function len():stdgo.GoInt

(view code)

SortedMap function less

function less( _i:stdgo.GoInt, _j:stdgo.GoInt):Bool

(view code)

SortedMap function swap

function swap( _i:stdgo.GoInt, _j:stdgo.GoInt):Void

(view code)