key

package
v0.0.0-...-a8d7af0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b interface{}) bool

Equal compares two arbitrary interfaces for equality.

func Hash

func Hash(seed maphash.Seed, k Key) uint64

Hash will hash a key. Can be used with github.com/aristanetworks/gomap.Map.

func HashInterface

func HashInterface(v interface{}) uintptr

HashInterface computes the hash of a Key

func SortedKeys

func SortedKeys(m map[string]interface{}) []string

SortedKeys returns the keys of the given map, in a sorted order.

func StringKey

func StringKey(k Key) string

StringKey generates a String suitable to be used as a key in a string index by calling k.StringKey, if available, otherwise it calls k.String. StringKey returns the same results as StringifyInterface(k.Key()) and should be preferred over StringifyInterface.

func StringifyInterface deprecated

func StringifyInterface(key interface{}) (string, error)

StringifyInterface transforms an arbitrary interface into a string representation suitable to be used as a key, such as in a JSON object, or as a path element.

Deprecated: Use StringKey instead.

Types

type Comparable

type Comparable interface {
	// Equal returns true if this object is equal to the other one.
	Equal(other interface{}) bool
}

Comparable types have an equality-testing method.

type Hashable

type Hashable interface {
	Hash() uint64
	Equal(other interface{}) bool
}

Hashable represents the key for an entry in a Map that cannot natively be hashed

type Key

type Key interface {
	Key() interface{}
	String() string
	Equal(other interface{}) bool
}

Key represents the Key in the updates and deletes of the Notification objects. The only reason this exists is that Go won't let us define our own hash function for non-hashable types, and unfortunately we need to be able to index maps by map[string]interface{} objects and slices by []interface{} objects.

func New

func New(intf interface{}) Key

New wraps the given value in a Key. This function panics if the value passed in isn't allowed in a Key or doesn't implement value.Value.

type Map

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

Map allows the indexing of entries with arbitrary key types, so long as the keys are either hashable natively or implement Hashable

func NewMap

func NewMap(keysAndVals ...interface{}) *Map

NewMap creates a new Map from a list of key-value pairs, so long as the list is of even length.

func (*Map) Del

func (m *Map) Del(k interface{})

Del removes an entry with key k from the Map

func (*Map) Equal

func (m *Map) Equal(other interface{}) bool

Equal compares two Maps

func (*Map) Get

func (m *Map) Get(k interface{}) (interface{}, bool)

Get retrieves the value stored with key k from the Map

func (*Map) Hash

func (m *Map) Hash() uint64

Hash returns the hash value of this Map

func (*Map) Iter

func (m *Map) Iter(f func(k, v interface{}) error) error

Iter applies func f to every key-value pair in the Map

func (*Map) KeyString

func (m *Map) KeyString() string

KeyString returns a string that is suitable to be used as a key in an index of strings.

func (*Map) Keys

func (m *Map) Keys() []interface{}

Keys returns a list of all keys in the Map

func (*Map) Len

func (m *Map) Len() int

Len returns the length of the Map

func (*Map) Set

func (m *Map) Set(k, v interface{})

Set adds a key-value pair to the Map

func (*Map) String

func (m *Map) String() string

String outputs the string representation of the map

func (*Map) Values

func (m *Map) Values() []interface{}

Values returns a list of all values in the Map

type Path

type Path []Key

Path represents a path decomposed into elements where each element is a Key. A Path can be interpreted as either absolute or relative depending on how it is used.

func (Path) Equal

func (p Path) Equal(other interface{}) bool

Equal returns whether a Path is equal to @other.

func (Path) MarshalJSON

func (p Path) MarshalJSON() ([]byte, error)

MarshalJSON marshals a Path to JSON.

func (Path) String

func (p Path) String() string

String returns the Path as an absolute path string.

type Pointer

type Pointer interface {
	Pointer() Path
}

Pointer is a pointer to a path.

func NewPointer

func NewPointer(path Path) Pointer

NewPointer creates a new pointer to a path.

Jump to

Keyboard shortcuts

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