mapcoll

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SERIALIZED_MAP_PATTERN_KEY_KEY = "key"
	SERIALIZED_MAP_PATTERN_VAL_KEY = "value"
)
View Source
const (
	INITIAL_MAP_KEY_BUF = 2000
)

Variables

View Source
var (
	ErrMapEntryListShouldHaveEvenLength     = errors.New(`flat map entry list should have an even length: ["k1", 1,  "k2", 2]`)
	ErrMapCanOnlyContainKeysWithFastId      = errors.New("a Map can only contain keys having a fast id")
	ErrSetCanOnlyContainRepresentableValues = errors.New("a Map can only contain representable values")
	ErrKeysShouldBeImmutable                = errors.New("keys should be immutable")
	ErrKeyDoesMatchKeyPattern               = errors.New("provided key does not match the key pattern")
	ErrValueDoesMatchValuePattern           = errors.New("provided value does not match the value pattern")
	ErrEntryAlreadyExists                   = errors.New("entry already exists")
	ErrValueWithSameKeyAlreadyPresent       = errors.New("provided value has the same key as an already present element")
)
View Source
var (
	MAP_PATTERN = &core.TypePattern{
		Name:          "Map",
		Type:          reflect.TypeOf((*Map)(nil)),
		SymbolicValue: coll_symbolic.ANY_MAP,
		CallImpl: func(typePattern *core.TypePattern, values []core.Serializable) (core.Pattern, error) {
			switch len(values) {
			case 0:
				return nil, commonfmt.FmtMissingArgument("key pattern and value pattern")
			case 1:
				return nil, commonfmt.FmtMissingArgument("value pattern")
			}

			keyPattern, ok := values[0].(core.Pattern)
			if !ok {
				return nil, core.FmtErrInvalidArgumentAtPos(keyPattern, 0)
			}

			valuePattern, ok := values[1].(core.Pattern)
			if !ok {
				return nil, core.FmtErrInvalidArgumentAtPos(keyPattern, 1)
			}

			return NewMapPattern(MapConfig{
				Key:   keyPattern,
				Value: valuePattern,
			}), nil
		},
		SymbolicCallImpl: func(ctx *symbolic.Context, values []symbolic.Value) (symbolic.Pattern, error) {
			switch len(values) {
			case 0:
				return nil, commonfmt.FmtMissingArgument("key pattern and value pattern")
			case 1:
				return nil, commonfmt.FmtMissingArgument("value pattern")
			}

			keyPattern, ok := values[0].(symbolic.Pattern)
			key := symbolic.AsSerializable(keyPattern.SymbolicValue())
			if !ok || !utils.Implements[symbolic.Serializable](key) {
				return nil, commonfmt.FmtErrInvalidArgumentAtPos(1, "key pattern should not match values that are not serializable")
			}

			if key.IsMutable() {
				return nil, commonfmt.FmtErrInvalidArgumentAtPos(1, "key pattern should not match values that are not mutable")
			}

			valuePattern, ok := values[1].(symbolic.Pattern)
			if !ok || !utils.Implements[symbolic.Serializable](symbolic.AsSerializable(valuePattern.SymbolicValue())) {
				return nil, commonfmt.FmtErrInvalidArgumentAtPos(1, "value pattern cannot match values that are not serializable")
			}

			return coll_symbolic.NewMapPattern(keyPattern, valuePattern), nil
		},
	}

	MAP_PATTERN_PATTERN = &core.TypePattern{
		Name:          "map-pattern",
		Type:          reflect.TypeOf((*MapPattern)(nil)),
		SymbolicValue: coll_symbolic.ANY_MAP_PATTERN,
	}
)

Functions

func DeserializeMapPattern

func DeserializeMapPattern(ctx *core.Context, it *jsoniter.Iterator, pattern core.Pattern, try bool) (_ core.Pattern, finalErr error)

Types

type Map

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

func NewMap

func NewMap(ctx *core.Context, flatEntries *core.List, configParam *core.OptionalParam[*core.Object]) *Map

func NewMapWithConfig

func NewMapWithConfig(ctx *core.Context, flatEntries *core.List, config MapConfig) *Map

func (*Map) Contains

func (m *Map) Contains(ctx *core.Context, value core.Serializable) bool

func (*Map) Equal

func (m *Map) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*Map) Get

func (m *Map) Get(ctx *core.Context, keyVal core.Serializable) (core.Value, core.Bool)

func (*Map) GetElementByKey

func (m *Map) GetElementByKey(ctx *core.Context, pathKey core.ElementKey) (core.Serializable, error)

func (*Map) GetGoMethod

func (m *Map) GetGoMethod(name string) (*core.GoFunction, bool)

func (*Map) Has

func (m *Map) Has(ctx *core.Context, keyVal core.Serializable) core.Bool

func (*Map) Insert

func (m *Map) Insert(ctx *core.Context, key, value core.Serializable) error

func (*Map) IsEmpty

func (m *Map) IsEmpty(ctx *core.Context) bool

func (*Map) IsMutable

func (m *Map) IsMutable() bool

func (*Map) IsSharable

func (m *Map) IsSharable(originState *core.GlobalState) (bool, string)

func (*Map) IsShared

func (m *Map) IsShared() bool

func (*Map) Iterator

func (s *Map) Iterator(ctx *core.Context, config core.IteratorConfiguration) core.Iterator

func (*Map) Migrate

func (m *Map) Migrate(ctx *core.Context, key core.Path, migration *core.FreeEntityMigrationArgs) (core.Value, error)

func (*Map) PrettyPrint

func (m *Map) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*Map) Prop

func (m *Map) Prop(ctx *core.Context, name string) core.Value

func (*Map) PropertyNames

func (*Map) PropertyNames(ctx *core.Context) []string

func (*Map) Remove

func (m *Map) Remove(ctx *core.Context, key core.Serializable)

func (*Map) Set

func (m *Map) Set(ctx *core.Context, key, value core.Serializable)

func (*Map) SetProp

func (*Map) SetProp(ctx *core.Context, name string, value core.Value) error

func (*Map) SetURLOnce

func (m *Map) SetURLOnce(ctx *core.Context, url core.URL) error

func (*Map) Share

func (m *Map) Share(originState *core.GlobalState)

func (*Map) SmartLock

func (m *Map) SmartLock(state *core.GlobalState)

func (*Map) SmartUnlock

func (m *Map) SmartUnlock(state *core.GlobalState)

func (*Map) ToSymbolicValue

func (m *Map) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*Map) URL

func (m *Map) URL() (core.URL, bool)

func (*Map) WriteJSONRepresentation

func (m *Map) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

type MapConfig

type MapConfig struct {
	Key, Value core.Pattern
}

func (MapConfig) Equal

func (c MapConfig) Equal(ctx *core.Context, otherConfig MapConfig, alreadyCompared map[uintptr]uintptr, depth int) bool

type MapPattern

type MapPattern struct {
	core.NotCallablePatternMixin
	// contains filtered or unexported fields
}

func NewMapPattern

func NewMapPattern(config MapConfig) *MapPattern

func (*MapPattern) DefaultValue

func (p *MapPattern) DefaultValue(ctx *core.Context) (core.Value, error)

func (*MapPattern) Equal

func (p *MapPattern) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*MapPattern) GetMigrationOperations

func (p *MapPattern) GetMigrationOperations(ctx *core.Context, next core.Pattern, pseudoPath string) ([]core.MigrationOp, error)

func (*MapPattern) IsMutable

func (p *MapPattern) IsMutable() bool

func (*MapPattern) Iterator

func (p *MapPattern) Iterator(ctx *core.Context, config core.IteratorConfiguration) core.Iterator

func (*MapPattern) PrettyPrint

func (p *MapPattern) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*MapPattern) Random

func (p *MapPattern) Random(ctx *core.Context, options ...core.Option) core.Value

func (*MapPattern) StringPattern

func (p *MapPattern) StringPattern() (core.StringPattern, bool)

func (*MapPattern) Test

func (patt *MapPattern) Test(ctx *core.Context, v core.Value) bool

func (*MapPattern) ToSymbolicValue

func (p *MapPattern) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*MapPattern) WriteJSONRepresentation

func (p *MapPattern) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

Jump to

Keyboard shortcuts

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