setcoll

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

Documentation

Index

Constants

View Source
const (
	AddElem core.SpecificMutationKind = iota + 1
	RemoveElem
)
View Source
const (
	SERIALIZED_SET_PATTERN_ELEM_KEY       = "element"
	SERIALIZED_SET_PATTERN_UNIQUENESS_KEY = "uniqueness"
)
View Source
const (
	DEFAULT_WATCHING_DEPTH = core.ShallowWatching
)
View Source
const (
	INITIAL_SET_KEY_BUF = 2000
)

Variables

View Source
var (
	SET_PATTERN = &core.TypePattern{
		Name:          "Set",
		Type:          reflect.TypeOf((*Set)(nil)),
		SymbolicValue: coll_symbolic.ANY_SET,
		CallImpl: func(typePattern *core.TypePattern, values []core.Serializable) (core.Pattern, error) {
			switch len(values) {
			case 0:
				return nil, commonfmt.FmtMissingArgument("element pattern")
			case 1:
				return nil, commonfmt.FmtMissingArgument("uniqueness")
			}

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

			uniqueness, ok := common.UniquenessConstraintFromValue(values[1])
			if !ok {
				return nil, core.FmtErrInvalidArgumentAtPos(elementPattern, 1)
			}

			return NewSetPattern(SetConfig{
				Element:    elementPattern,
				Uniqueness: uniqueness,
			}), nil
		},
		SymbolicCallImpl: func(ctx *symbolic.Context, values []symbolic.Value) (symbolic.Pattern, error) {
			switch len(values) {
			case 0:
				return nil, commonfmt.FmtMissingArgument("element pattern")
			case 1:
				return nil, commonfmt.FmtMissingArgument("uniqueness")
			}

			elementPattern, ok := values[0].(symbolic.Pattern)
			if !ok {
				return nil, commonfmt.FmtErrInvalidArgumentAtPos(0, "a pattern is expected")
			}

			uniqueness, err := common.UniquenessConstraintFromSymbolicValue(values[1], elementPattern)
			if err != nil {
				return nil, commonfmt.FmtErrInvalidArgumentAtPos(1, err.Error())
			}

			return coll_symbolic.NewSetPatternWithElementPatternAndUniqueness(elementPattern, &uniqueness), nil
		},
	}

	SET_PATTERN_PATTERN = &core.TypePattern{
		Name:          "set-pattern",
		Type:          reflect.TypeOf((*SetPattern)(nil)),
		SymbolicValue: coll_symbolic.ANY_SET_PATTERN,
	}
)
View Source
var (
	ErrSetCanOnlyContainRepresentableValues           = errors.New("a Set can only contain representable values")
	ErrValueDoesMatchElementPattern                   = errors.New("provided value does not match the element pattern")
	ErrValueWithSameKeyAlreadyPresent                 = errors.New("provided value has the same key as an already present element")
	ErrURLUniquenessOnlySupportedIfPersistedSharedSet = errors.New("URL uniqueness is only supported if the Set is persisted and shared")
	ErrCannotAddDifferentElemWithSamePropertyValue    = errors.New("cannot add different element with same property value")
	ErrPropertyUsedForUniquenessNoPresentInPattern    = errors.New("property used for uniqueness is not present in element pattern")
)

Functions

func DeserializeSetPattern

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

func NewAddElemMutation

func NewAddElemMutation(path core.Path) core.Mutation

func NewRemoveElemMutation

func NewRemoveElemMutation(path core.Path) core.Mutation

Types

type Set

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

func NewSet

func NewSet(ctx *core.Context, elements core.Iterable, configParam *core.OptionalParam[*core.Object]) *Set

func NewSetWithConfig

func NewSetWithConfig(ctx *core.Context, elements core.Iterable, config SetConfig) *Set

func (*Set) Add

func (set *Set) Add(ctx *core.Context, elem core.Serializable)

func (*Set) Contains

func (set *Set) Contains(ctx *core.Context, value core.Serializable) bool

func (*Set) Equal

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

func (*Set) Get

func (set *Set) Get(ctx *core.Context, keyVal core.StringLike) (core.Value, core.Bool)

func (*Set) GetElementByKey

func (set *Set) GetElementByKey(ctx *core.Context, pathKey core.ElementKey) (core.Serializable, error)

func (*Set) GetGoMethod

func (f *Set) GetGoMethod(name string) (*core.GoFunction, bool)

func (*Set) Has

func (set *Set) Has(ctx *core.Context, elem core.Serializable) core.Bool

func (*Set) IsEmpty

func (set *Set) IsEmpty(ctx *core.Context) bool

func (*Set) IsMutable

func (s *Set) IsMutable() bool

func (*Set) IsSharable

func (s *Set) IsSharable(originState *core.GlobalState) (bool, string)

func (*Set) IsShared

func (s *Set) IsShared() bool

func (*Set) Iterator

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

func (*Set) Migrate

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

func (*Set) OnMutation

func (*Set) PrettyPrint

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

func (*Set) Prop

func (s *Set) Prop(ctx *core.Context, name string) core.Value

func (*Set) PropertyNames

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

func (*Set) Remove

func (set *Set) Remove(ctx *core.Context, elem core.Serializable)

func (*Set) RemoveMutationCallback

func (set *Set) RemoveMutationCallback(ctx *core.Context, handle core.CallbackHandle)

func (*Set) RemoveMutationCallbackMicrotasks

func (set *Set) RemoveMutationCallbackMicrotasks(ctx *core.Context)

func (*Set) SetProp

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

func (*Set) SetURLOnce

func (set *Set) SetURLOnce(ctx *core.Context, url core.URL) error

func (*Set) Share

func (s *Set) Share(originState *core.GlobalState)

func (*Set) SmartLock

func (s *Set) SmartLock(state *core.GlobalState)

func (*Set) SmartUnlock

func (s *Set) SmartUnlock(state *core.GlobalState)

func (*Set) ToSymbolicValue

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

func (*Set) URL

func (set *Set) URL() (core.URL, bool)

func (*Set) Watcher

func (set *Set) Watcher(ctx *core.Context, config core.WatcherConfiguration) core.Watcher

func (*Set) WriteJSONRepresentation

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

type SetConfig

type SetConfig struct {
	Element    core.Pattern
	Uniqueness common.UniquenessConstraint
}

func (SetConfig) Equal

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

type SetPattern

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

func NewSetPattern

func NewSetPattern(config SetConfig) *SetPattern

func (*SetPattern) DefaultValue

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

func (*SetPattern) Equal

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

func (*SetPattern) GetMigrationOperations

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

func (*SetPattern) IsMutable

func (p *SetPattern) IsMutable() bool

func (*SetPattern) Iterator

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

func (*SetPattern) PrettyPrint

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

func (*SetPattern) Random

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

func (*SetPattern) StringPattern

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

func (*SetPattern) Test

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

func (*SetPattern) ToSymbolicValue

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

func (*SetPattern) WriteJSONRepresentation

func (p *SetPattern) 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