orderedmap

package
v1.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT, MIT Imports: 5 Imported by: 0

README

orderedmap

forked from iancoleman/orderedmap v0.3.0

A golang data type equivalent to python's collections.OrderedDict

Retains order of keys in maps

Can be JSON serialized / deserialized

Usage

example

Caveats

  • OrderedMap only takes strings for the key, as per the JSON spec.

Tests

go test

Alternatives

None of the alternatives offer JSON serialization.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByPair

type ByPair struct {
	Pairs    []*Pair
	LessFunc func(a *Pair, j *Pair) bool
}

func (ByPair) Len

func (a ByPair) Len() int

func (ByPair) Less

func (a ByPair) Less(i, j int) bool

func (ByPair) Swap

func (a ByPair) Swap(i, j int)

type ByPairOf added in v1.0.3

type ByPairOf[K comparable, V any] struct {
	Pairs    []*PairOf[K, V]
	LessFunc func(a *PairOf[K, V], j *PairOf[K, V]) bool
}

func (ByPairOf[K, V]) Len added in v1.0.3

func (a ByPairOf[K, V]) Len() int

func (ByPairOf[K, V]) Less added in v1.0.3

func (a ByPairOf[K, V]) Less(i, j int) bool

func (ByPairOf[K, V]) Swap added in v1.0.3

func (a ByPairOf[K, V]) Swap(i, j int)

type OrderedMap

type OrderedMap struct {
	// contains filtered or unexported fields
}

func New

func New() *OrderedMap

func (*OrderedMap) Delete

func (o *OrderedMap) Delete(key string)

func (*OrderedMap) Get

func (o *OrderedMap) Get(key string) (interface{}, bool)

func (*OrderedMap) Keys

func (o *OrderedMap) Keys() []string

func (OrderedMap) MarshalJSON

func (o OrderedMap) MarshalJSON() ([]byte, error)

func (*OrderedMap) Set

func (o *OrderedMap) Set(key string, value interface{})

func (*OrderedMap) SetEscapeHTML

func (o *OrderedMap) SetEscapeHTML(on bool)

func (*OrderedMap) Sort

func (o *OrderedMap) Sort(lessFunc func(a *Pair, b *Pair) bool)

Sort the map using your sort func

func (*OrderedMap) SortKeys

func (o *OrderedMap) SortKeys(sortFunc ...func(keys []string))

SortKeys Sort the map keys using your sort func

func (*OrderedMap) UnmarshalJSON

func (o *OrderedMap) UnmarshalJSON(b []byte) error

func (*OrderedMap) Values

func (o *OrderedMap) Values() map[string]interface{}

type OrderedMapOf added in v1.0.3

type OrderedMapOf[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewOf added in v1.0.3

func NewOf[K comparable, V any]() *OrderedMapOf[K, V]

func (*OrderedMapOf[K, V]) Clone added in v1.0.3

func (o *OrderedMapOf[K, V]) Clone() *OrderedMapOf[K, V]

func (*OrderedMapOf[K, V]) Delete added in v1.0.3

func (o *OrderedMapOf[K, V]) Delete(key K)

func (*OrderedMapOf[K, V]) Get added in v1.0.3

func (o *OrderedMapOf[K, V]) Get(key K) (V, bool)

func (*OrderedMapOf[K, V]) Keys added in v1.0.3

func (o *OrderedMapOf[K, V]) Keys() []K

func (*OrderedMapOf[K, V]) MustGet added in v1.0.3

func (o *OrderedMapOf[K, V]) MustGet(key K) V

func (*OrderedMapOf[K, V]) Set added in v1.0.3

func (o *OrderedMapOf[K, V]) Set(key K, value V)

func (*OrderedMapOf[K, V]) Sort added in v1.0.3

func (o *OrderedMapOf[K, V]) Sort(lessFunc func(a *PairOf[K, V], b *PairOf[K, V]) bool)

Sort the map using your sort func

func (*OrderedMapOf[K, V]) SortKeys added in v1.0.3

func (o *OrderedMapOf[K, V]) SortKeys(sortFunc func(keys []K))

SortKeys Sort the map keys using your sort func

func (*OrderedMapOf[K, V]) ToMap added in v1.0.3

func (o *OrderedMapOf[K, V]) ToMap() map[K]V

func (*OrderedMapOf[K, V]) Values added in v1.0.3

func (o *OrderedMapOf[K, V]) Values() map[K]V

type Pair

type Pair struct {
	// contains filtered or unexported fields
}

func (*Pair) Key

func (kv *Pair) Key() string

func (*Pair) Value

func (kv *Pair) Value() interface{}

type PairOf added in v1.0.3

type PairOf[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*PairOf[K, V]) Key added in v1.0.3

func (kv *PairOf[K, V]) Key() K

func (*PairOf[K, V]) Value added in v1.0.3

func (kv *PairOf[K, V]) Value() V

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL