featuremap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FeatureMap

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

FeatureMap has similar operations as the default map, but maintains the order of inserted keys. Similar to map, all single key operations e.g. get, set and delete runs at O(1). Although the JSON spec says the keys order of an object should not matter, sometimes the order of JSON objects and their keys matters when printing them for humans. Therefore we have to maintain the object keys in the same order as they come in.

Disclaimer, same as Go's default map, FeatureMap is not safe for concurrent use. If you need atomic access, may use a sync.Mutex to synchronize.

More references may be found below.

Go maps in action     https://blog.golang.org/go-maps-in-action
JSON and Go           https://blog.golang.org/json-and-go
Go-Ordered-JSON       https://github.com/virtuald/go-ordered-json
Python OrderedDict    https://github.com/python/cpython/blob/2.7/Lib/collections.py#L38
port OrderedDict      https://github.com/cevaris/ordered_map
original proposal     https://gitlab.com/c0b/go-ordered-json/-/blob/49bbdab258c2e707b671515c36308ea48134970d/ordered.go

func New

func New() *FeatureMap

func (*FeatureMap) Delete

func (fm *FeatureMap) Delete(key string) (value interface{}, ok bool)

func (*FeatureMap) EntriesIter

func (fm *FeatureMap) EntriesIter() func() (*KVPair, bool)

func (*FeatureMap) EntriesReverseIter

func (fm *FeatureMap) EntriesReverseIter() func() (*KVPair, bool)

func (*FeatureMap) Get

func (fm *FeatureMap) Get(key string) interface{}

func (*FeatureMap) GetValue

func (fm *FeatureMap) GetValue(key string) (value interface{}, ok bool)

func (*FeatureMap) Has

func (fm *FeatureMap) Has(key string) bool

func (*FeatureMap) Keys

func (fm *FeatureMap) Keys() []string

func (*FeatureMap) Len

func (fm *FeatureMap) Len() int

func (*FeatureMap) MarshalJSON

func (fm *FeatureMap) MarshalJSON() ([]byte, error)

func (*FeatureMap) Set

func (fm *FeatureMap) Set(key string, value interface{})

func (*FeatureMap) UnmarshalJSON

func (fm *FeatureMap) UnmarshalJSON(data []byte) error

func (*FeatureMap) Values

func (fm *FeatureMap) Values() []interface{}

type KVPair

type KVPair struct {
	Key   string
	Value interface{}
}

KVPair for initializing from a list of key-value pairs, or for looping entries in the same order.

Jump to

Keyboard shortcuts

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