cmap

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CMKey

type CMKey string

CMKey is the map key type.

type CMap

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

CMap is a wrapper around map[CMKey]Value which is safe for concurrent read and write.

func MakeCMap

func MakeCMap(capacity int) CMap

MakeCMap creates a new CMap with capacity set.

func NewCMap

func NewCMap(from ...Value) CMap

NewCMap creates a new CMap. You may optionally pass any number of Values, which will be added to this map.

func NewCMapFromMap

func NewCMapFromMap(from ...map[CMKey]Value) CMap

NewCMapFromMap creates a new CMap. You may optionally pass any number of map[CMKey]Values, which will be merged key-wise into the new CMap, with keys from the right-most map taking precedence.

func (CMap) Add

func (m CMap) Add(v Value) (ok bool)

Add adds a (k, v) pair into a map if it is not already there. Returns true if the value was added, false if not.

func (CMap) AddAll

func (m CMap) AddAll(from CMap) (conflicting CMKey, success bool)

AddAll returns (zero CMKey, true) if all entries from the passed in CMap have different keys and all are added to this CMap. If any of the keys conflict, nothing will be added to this CMap and AddAll will return the conflicting CMKey and false.

func (CMap) Any

func (m CMap) Any(predicate func(Value) bool) (Value, bool)

Any returns (a single Value matching predicate, true), if there are any Values matching predicate in CMap. Otherwise returns (zero Value, false).

func (CMap) Clone

func (m CMap) Clone() CMap

Clone returns a pairwise copy of CMap.

func (CMap) Filter

func (m CMap) Filter(predicate func(Value) bool) CMap

Filter returns a new CMap containing only the entries where the predicate returns true for the given value. A nil predicate is equivalent to calling Clone.

func (CMap) FilteredSnapshot

func (m CMap) FilteredSnapshot(predicate func(Value) bool) map[CMKey]Value

FilteredSnapshot returns a moment-in-time filtered copy of the current underlying map[CMKey]Value. (CMKey, Value) pairs are included if they satisfy predicate.

func (CMap) Get

func (m CMap) Get(key CMKey) (v Value, ok bool)

Get returns (value, true) if k is in the map, or (zero value, false) otherwise.

func (CMap) GetAll

func (m CMap) GetAll() map[CMKey]Value

GetAll returns SnapShot (it allows hy to marshal CMap).

func (CMap) Keys

func (m CMap) Keys() []CMKey

Keys returns a slice containing all the keys in the map.

func (CMap) Len

func (m CMap) Len() int

Len returns number of elements in a map.

func (CMap) Merge

func (m CMap) Merge(other CMap) CMap

Merge returns a new CMap with all entries from this CMap and the other. If any keys in other match keys in this *CMap, keys from other will appear in the returned *CMap.

func (CMap) MustAdd

func (m CMap) MustAdd(v Value)

MustAdd is a wrapper around Add which panics whenever Add returns false.

func (CMap) Remove

func (m CMap) Remove(key CMKey)

Remove value for a key k if present, a no-op otherwise.

func (CMap) Set

func (m CMap) Set(key CMKey, value Value)

Set sets the value of index k to v.

func (*CMap) SetAll

func (m *CMap) SetAll(v map[CMKey]Value)

SetAll sets the internal map (it allows hy to unmarshal CMap). Note: SetAll is the only method that is not safe for concurrent access.

func (CMap) Single

func (m CMap) Single(predicate func(Value) bool) (Value, bool)

Single returns (the single Value satisfying predicate, true), if there is exactly one Value satisfying predicate in CMap. Otherwise, returns (zero Value, false).

func (CMap) Snapshot

func (m CMap) Snapshot() map[CMKey]Value

Snapshot returns a moment-in-time copy of the current underlying map[CMKey]Value.

type Value

type Value string

Value is the map value type.

func (Value) Clone added in v0.0.3

func (v Value) Clone() Value

Clone returns a deep copy of this value.

func (Value) ID

func (v Value) ID() CMKey

ID returns the Key identifying this Value. Note: this is in a separate file so that it doesn't get copied.

Jump to

Keyboard shortcuts

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