storage

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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMut       = fmt.Errorf("setting and/or overwriting elements disallowed")
	ErrNoOverwrite = fmt.Errorf("overwriting existing elements is not allowed")
)

Functions

func GetIDs

func GetIDs[T any](s Storage, ids ...ID) (map[ID]T, error)

func GetSlice

func GetSlice[T any](s Storage, id ID) ([]T, error)

func GetSliceOf

func GetSliceOf[T any](s Storage, ids []ID) (map[ID]T, error)

func GetVar

func GetVar[T any](s Storage, id ID) (T, error)

func HasVar

func HasVar[T any](s Storage, id ID) bool

func SetVar

func SetVar[T any](s Storage, id ID, val T) error

func SetVarAtKey

func SetVarAtKey[K, T any](k Keyed[K], key K, val T) error

func SetVarAtKeys

func SetVarAtKeys[K comparable, T any](k Keyed[K], vals map[K]T) error

func SetVars

func SetVars[T any](s Storage, vals map[ID]T) error

func VarAtKey

func VarAtKey[K, T any](k Keyed[K], key K) (T, error)

Types

type AllowedOp

type AllowedOp int

ENUM(

Get
Set
Overwrite

)

const (
	// AllowedOpGet is a AllowedOp of type Get.
	AllowedOpGet AllowedOp = iota
	// AllowedOpSet is a AllowedOp of type Set.
	AllowedOpSet
	// AllowedOpOverwrite is a AllowedOp of type Overwrite.
	AllowedOpOverwrite
)

func ParseAllowedOp

func ParseAllowedOp(name string) (AllowedOp, error)

ParseAllowedOp attempts to convert a string to a AllowedOp.

func (AllowedOp) EnsureAllowed

func (op AllowedOp) EnsureAllowed(other AllowedOp) error

func (AllowedOp) EnsureOverwrite

func (op AllowedOp) EnsureOverwrite() error

func (AllowedOp) EnsureSet

func (op AllowedOp) EnsureSet() error

func (AllowedOp) IsAllowed

func (op AllowedOp) IsAllowed(other AllowedOp) bool

func (AllowedOp) MarshalText

func (x AllowedOp) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (AllowedOp) String

func (x AllowedOp) String() string

String implements the Stringer interface.

func (*AllowedOp) UnmarshalText

func (x *AllowedOp) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type AnyMap

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

func (AnyMap) GetVar

func (a AnyMap) GetVar(aset AnySet) (any, bool, error)

func (AnyMap) HasVar

func (a AnyMap) HasVar(aset AnySet) (bool, error)

func (AnyMap) SetVar

func (a AnyMap) SetVar(aset AnySet, val any) error

type AnySet

type AnySet map[any]empty

func AnySetFromSlice

func AnySetFromSlice(sl AnySlice) AnySet

func NewAnySet

func NewAnySet(args ...any) AnySet

type AnySetToID

type AnySetToID interface {
	ConvertToID(AnySet) (ID, error)
}

type AnySlice

type AnySlice []any

type Cache

type Cache struct {
	MapType map[reflect.Type]reflect.Type
	Maps    map[reflect.Type]DynamicMap
}

type Dynamic

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

func (Dynamic) GetMap

func (d Dynamic) GetMap(id ID, val reflect.Type) DynamicMap

func (Dynamic) GetMapType

func (d Dynamic) GetMapType(val reflect.Type) reflect.Type

type DynamicMap

type DynamicMap interface {
	GetID(ID) (any, bool)
	HasID(ID) bool
	SetIS(ID, any) error
}

type ErrMismatchedTypes

type ErrMismatchedTypes struct {
	Expected, Got reflect.Type
	ID            ID
}

func (ErrMismatchedTypes) Error

func (err ErrMismatchedTypes) Error() string

func (ErrMismatchedTypes) FormatError

func (err ErrMismatchedTypes) FormatError(w io.Writer) error

type ErrNoSuchVar

type ErrNoSuchVar struct {
	Type reflect.Type
	ID   ID
}

func (ErrNoSuchVar) Error

func (err ErrNoSuchVar) Error() string

func (ErrNoSuchVar) FormatError

func (err ErrNoSuchVar) FormatError(w io.Writer) error

type ID

type ID uint64

type Keyed

type Keyed[K any] struct {
	// contains filtered or unexported fields
}

func NewKeyed

func NewKeyed[K any](s Storage, conv func(K) (ID, error)) Keyed[K]

type Map

type Map[T any] struct {
	// contains filtered or unexported fields
}

func (Map[T]) Get

func (m Map[T]) Get(id ID) (T, bool)

func (Map[T]) Has

func (m Map[T]) Has(id ID) bool

func (Map[T]) Set

func (m Map[T]) Set(id ID, val T)

type MapMethods

type MapMethods struct {
	GetVal func(dm DynamicMap, keys []any) (any, bool)
	SetVal func(dm DynamicMap, keys []any, val any)
}

type Of

type Of[T any] interface {
	Get(id ID) (T, bool)
	Set(id ID, val T)
	Has(id ID) bool
}

type Raw

type Raw interface {
	GetVar(reflect.Type, ID) (any, bool)
	HasVar(reflect.Type, ID) bool
	SetVar(reflect.Type, ID, any) error
}

type RawMap

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

func NewMapStorage

func NewMapStorage() RawMap

func (RawMap) GetVar

func (m RawMap) GetVar(typ reflect.Type, id ID) (any, bool)

func (RawMap) HasVar

func (m RawMap) HasVar(typ reflect.Type, id ID) bool

func (RawMap) SetVar

func (m RawMap) SetVar(typ reflect.Type, id ID, data any) error

type RawMutex

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

func (*RawMutex) GetVar

func (m *RawMutex) GetVar(typ reflect.Type, id ID) (any, bool)

func (*RawMutex) HasVar

func (m *RawMutex) HasVar(typ reflect.Type, id ID) bool

func (*RawMutex) SetVar

func (m *RawMutex) SetVar(typ reflect.Type, id ID, data any) error

type RawSet

type RawSet interface {
	GetVar(AnySet) (any, bool, error)
	HasVar(AnySet) (bool, error)
	SetVar(AnySet, any) error
}

type RuntimeMethods

type RuntimeMethods struct {
	NewMap   func(mapType reflect.Type) DynamicMap
	HashKeys func(keys []any) (ID, error)
	HashVal  func(val any) (ID, error)
}

type Storage

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

func NewStorage

func NewStorage(raw Raw, ops AllowedOp) Storage

Jump to

Keyboard shortcuts

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