mapping

package
v0.0.0-...-e537141 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MethodModes = setUpMethods()
	Modes       = struct {
		SetOnly *Methods
		Immut   *Methods
		Mut     *Methods
	}{
		Immut:   MethodModes[ModeImmut],
		SetOnly: MethodModes[ModeSetOnly],
		Mut:     MethodModes[ModeMut],
	}

	NoTransform = &NoTransformer{}
)
View Source
var EmptyVal = Empty{}
View Source
var ListWithNewline = ListFormat("'%s' is not found in map, alternatives: '%s'")
View Source
var PolicyFormat = NewPolicyViolationFormat("'%s' of map/dict element is not allowed")

Functions

func EnsureAllowed

func EnsureAllowed(m *Methods, pol PolicyKind) (err error)

func EnsureMut

func EnsureMut(m *Methods, mapHasKey bool) (err error)

func ExtendWith

func ExtendWith[T any](tr Transforms, dst, src map[string]T) error

func ExtendWithFormat

func ExtendWithFormat[T any](tr Transforms, dst, src map[string]T) error

func GetKeys

func GetKeys[K comparable, V any](m map[K]V) (keys []K)

func GetKeysOf

func GetKeysOf[K comparable, V any](m Of[K, V]) (keys []K)

func GetStringerKeys

func GetStringerKeys[K StringKey, V any](m map[K]V) []string

func MustGet

func MustGet[V any](mk OnMissingKey, m map[string]V, key string) (val V, err error)

func MustGetOf

func MustGetOf[V any](mk OnMissingKey, m Of[string, V], key string) (val V, err error)

func MustGetStringer

func MustGetStringer[K StringKey, V any](mk OnMissingKey, m map[K]V, key K) (val V, err error)

func MustSetCheckOverride

func MustSetCheckOverride[K comparable, V any](meth *Methods, m map[K]V, key K, val V) error

func NewLRU

func NewLRU[K comparable, V any](capacity int) *cache.Cache[K, V]

func NonOverlapping

func NonOverlapping[K comparable, V any](ex ExcludeKeys[K], m map[K]V) ([]int, bool)

func Reverse

func Reverse[K comparable, V comparable](m map[K]V) (rev map[V]K)

func Wrap

func Wrap[K comparable, V any](m map[K]V) wrapMap[K, V]

Types

type AnyHasher

type AnyHasher interface {
	SumBytes([]byte) ([]byte, error)
	Sum(any) ([]byte, error)
	Sum32(any) (uint32, error)
	Sum64(any) (uint64, error)
}

type Cache

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

func NewCache

func NewCache[K, V any](fn func(K) (V, error)) Cache[K, V]

func (Cache[K, V]) Get

func (c Cache[K, V]) Get(key K) (V, error)

func (*Cache[K, V]) SetHasher

func (c *Cache[K, V]) SetHasher(h AnyHasher)

type CacheLike

type CacheLike[K, V any] interface {
	Get(key K) (V, bool)
	Put(key K, val V)
	Remove(key K)
}

type DefaultMethods

type DefaultMethods [ModeTotal]*Methods

type Del

type Del[K any] interface {
	Del(key K)
}

type Empty

type Empty struct{}

type ErrMissingKey

type ErrMissingKey struct {
	Key any
}

func (*ErrMissingKey) Error

func (err *ErrMissingKey) Error() string

type ExcludeKeys

type ExcludeKeys[K comparable] struct {
	// contains filtered or unexported fields
}

func ExcludeKeysFromGroups

func ExcludeKeysFromGroups[K comparable](groups ...[]K) ExcludeKeys[K]

func (ExcludeKeys[K]) Get

func (ex ExcludeKeys[K]) Get(idx int) set.Set[K]

func (ExcludeKeys[K]) GetAsSlice

func (ex ExcludeKeys[K]) GetAsSlice(idx int) []K

func (ExcludeKeys[K]) GroupHas

func (ex ExcludeKeys[K]) GroupHas(key K) (int, bool)

type Hash

type Hash interface {
	io.Writer

	HashInt(int) error
	HashInt8(int8) error
	HashInt16(int16) error
	HashInt32(int16) error
	HashInt64(int16) error

	HashUInt8(uint8) error
	HashUInt16(uint16) error
	HashUInt32(uint16) error
	HashUInt64(uint16) error

	HashFloat32(float32) error
	HashFloat64(float64) error
}

type HashKind

type HashKind crypto.Hash

func (HashKind) NewHash

func (hk HashKind) NewHash() hash.Hash

type HashMaker

type HashMaker interface {
	NewHash() hash.Hash
}

type HashMethods

type HashMethods struct {
	WriteInt func(io.Writer, int) error
}

type Hashable

type Hashable interface {
	Hash(Hash) error
}

type IntMap

type IntMap[V any] struct {
	// contains filtered or unexported fields
}

IntMap maps uint64 keys to generic values. It implements the OfMut interface. It can be used as a map in situations where multiple types has to be used as keys, by hashing the value of the type used as a key to get an uint64 value to be used as a key.

func (*IntMap[V]) Del

func (im *IntMap[V]) Del(key uint64)

func (IntMap[V]) Each

func (im IntMap[V]) Each(fn func(key uint64, val V))

func (IntMap[V]) EachErr

func (im IntMap[V]) EachErr(fn func(key uint64, val V) error) error

func (IntMap[V]) Get

func (im IntMap[V]) Get(key uint64) (V, bool)

func (IntMap[V]) GetAnyKey

func (im IntMap[V]) GetAnyKey(h AnyHasher, key any) (V, bool, error)

func (IntMap[V]) Has

func (im IntMap[V]) Has(key uint64) bool

func (*IntMap[V]) HasAnyKey

func (im *IntMap[V]) HasAnyKey(h AnyHasher, key any) (bool, error)

func (*IntMap[V]) Set

func (im *IntMap[V]) Set(key uint64, val V)

func (*IntMap[V]) SetAnyKey

func (im *IntMap[V]) SetAnyKey(h AnyHasher, key any, val V) error

type KeyFormat

type KeyFormat string

func (KeyFormat) TransformKey

func (kf KeyFormat) TransformKey(key string) (string, error)

type KeyTransformer

type KeyTransformer interface {
	TransformKey(string) (string, error)
}

type LRUWithCreator

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

type ListKeys

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

func ListFormat

func ListFormat(format string) (l ListKeys)

func (ListKeys) HandleMissingAnyKey

func (l ListKeys) HandleMissingAnyKey(key any) (err error)

func (ListKeys) HandleMissingKey

func (l ListKeys) HandleMissingKey(keys []string, key string) (err error)

func (ListKeys) WithFormat

func (l ListKeys) WithFormat(format string) (lk ListKeys)

func (ListKeys) WithSeparator

func (l ListKeys) WithSeparator(sep string) (lk ListKeys)

type Map

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

func NewMap

func NewMap[K comparable, V any]() Map[K, V]

func NewMapCap

func NewMapCap[K comparable, V any](capacity int) Map[K, V]

func (Map[K, V]) Each

func (m Map[K, V]) Each(fn func(key K, val V))

func (Map[K, V]) EachErr

func (m Map[K, V]) EachErr(fn func(key K, val V) error) error

func (Map[K, V]) Get

func (m Map[K, V]) Get(key K) (V, bool)

func (Map[K, V]) Has

func (m Map[K, V]) Has(key K) bool

type Methods

func (*Methods) EnsureAllowed

func (m *Methods) EnsureAllowed(pol PolicyKind) error

type Mode

type Mode int

ENUM(

Mut
Immut
SetOnly
Total

)

const (
	// Mut PolicyMode = iota
	// Immut
	// SetOnly
	// PolicyModeTotal
	ModeMut Mode = iota
	ModeImmut
	ModeSetOnly
	ModeTotal
	NoOverwrite = ModeSetOnly
)

type Mut

type Mut[K, V any] interface {
	Of[K, V]
	Setter[K, V]
	Del[K]
}

type MutMap

type MutMap[K comparable, V any] struct {
	Map[K, V]
}

func NewMapMut

func NewMapMut[K comparable, V any]() MutMap[K, V]

func NewMapMutCap

func NewMapMutCap[K comparable, V any](capacity int) MutMap[K, V]

func (MutMap[K, V]) Del

func (m MutMap[K, V]) Del(key K)

func (MutMap[K, V]) Set

func (m MutMap[K, V]) Set(key K, val V)

type MutWithMethods

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

func (MutWithMethods[K, V]) Get

func (m MutWithMethods[K, V]) Get(key K) (V, bool)

func (MutWithMethods[K, V]) Has

func (m MutWithMethods[K, V]) Has(key K) bool

func (MutWithMethods[K, V]) Set

func (m MutWithMethods[K, V]) Set(key K, val V) error

func (MutWithMethods[K, V]) Update

func (m MutWithMethods[K, V]) Update(dict Of[K, V]) error

type NoTransformer

type NoTransformer struct{}

func (NoTransformer) TransformKey

func (NoTransformer) TransformKey(key string) (string, error)

type Numeric

type Numeric interface {
	constraints.Integer | constraints.Float
}

type Of

type Of[K, V any] interface {
	Has(key K) bool
	Get(key K) (V, bool)
	EachErr(fn func(key K, val V) error) error
	Each(fn func(key K, val V))
}

type OnMissingKey

type OnMissingKey interface {
	HandleMissingKey(keys []string, key string) (err error)
	HandleMissingAnyKey(key any) (err error)
}

type OnMissingType

type OnMissingType interface {
	HandleMissingType(t reflect.Type) (err error)
}

type OnPolicyViolation

type OnPolicyViolation interface {
	HandlePolicyViolation(pol PolicyKind) (err error)
}

type Policy

type Policy interface {
	PolicyAllowed(pol PolicyKind) (allowed bool)
	AllowPolicy(pol PolicyKind)
}

type PolicyKind

type PolicyKind int
const (
	PolicySet PolicyKind = iota
	PolicyOverwrite
	PolicyTotal
)

func (PolicyKind) String

func (p PolicyKind) String() (s string)

type PolicyMap

type PolicyMap map[PolicyKind]Empty

func NewPolicyMap

func NewPolicyMap(policies ...PolicyKind) (pm PolicyMap)

func (PolicyMap) AllowPolicy

func (pm PolicyMap) AllowPolicy(pol PolicyKind)

func (PolicyMap) PolicyAllowed

func (pm PolicyMap) PolicyAllowed(pol PolicyKind) (ok bool)

type PolicyModes

type PolicyModes [ModeTotal]Policy

type PolicyViolationFormat

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

func NewPolicyViolationFormat

func NewPolicyViolationFormat(format string) (p PolicyViolationFormat)

func (PolicyViolationFormat) HandlePolicyViolation

func (pv PolicyViolationFormat) HandlePolicyViolation(pol PolicyKind) (err error)

type RecursiveDeepHasher

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

func (RecursiveDeepHasher) Sum

func (rdh RecursiveDeepHasher) Sum(val any) ([]byte, error)

func (RecursiveDeepHasher) Sum32

func (rdh RecursiveDeepHasher) Sum32(val any) (uint32, error)

func (RecursiveDeepHasher) Sum64

func (rdh RecursiveDeepHasher) Sum64(val any) (uint64, error)

func (RecursiveDeepHasher) SumBytes

func (rdh RecursiveDeepHasher) SumBytes(b []byte) ([]byte, error)

type Ref

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

func EmptyRef

func EmptyRef[K comparable, V any](meth *Methods) Ref[K, V]

func ImmutRef

func ImmutRef[K comparable, V any](mapping map[K]V) Ref[K, V]

func NewRef

func NewRef[K comparable, V any](meth *Methods, mapping map[K]V) Ref[K, V]

func (Ref[K, V]) EnsureAllowed

func (r Ref[K, V]) EnsureAllowed(pol PolicyKind) error

func (Ref[K, V]) Get

func (r Ref[K, V]) Get(key K) (V, error)

func (Ref[K, V]) Insert

func (r Ref[K, V]) Insert(key K, val V) error

func (Ref[K, V]) MustGet

func (r Ref[K, V]) MustGet(key K) V

func (Ref[K, V]) MustInsert

func (r Ref[K, V]) MustInsert(key K, val V)

func (Ref[K, V]) TryGet

func (r Ref[K, V]) TryGet(key K) (V, bool)

func (Ref[K, V]) TryInsert

func (r Ref[K, V]) TryInsert(key K, val V) bool

type Setter

type Setter[K, V any] interface {
	Set(key K, val V)
}

type StringHash

type StringHash struct {
	AnyHasher
}

func (StringHash) Sum

func (sh StringHash) Sum(val any) (string, error)

type StringKey

type StringKey interface {
	comparable
	fmt.Stringer
}

type StringSet

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

func NewStringSet

func NewStringSet(strings ...string) (ss StringSet)

func (StringSet) Has

func (ss StringSet) Has(s string) (b bool)

type Transforms

type Transforms struct {
	KeyTransform KeyTransformer
	Methods      *Methods
}

type WrapHasher

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

Jump to

Keyboard shortcuts

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