keyset

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InclusiveKeySet

type InclusiveKeySet interface {
	KeySet
	// lists keys
	EnumKeys(func(k Key) bool) bool
	// number of unique keys
	Count() int
}

type Key

type Key = longbits.ByteString

type KeyList

type KeyList interface {
	// returns true when the given key is within the set
	Contains(Key) bool
	// lists keys
	EnumKeys(func(k Key) bool) bool
	// number of unique keys
	Count() int
}

A basic set of keys, that can be wrapped by an extra keyset logic.

type KeySet

type KeySet interface {
	// returns true when this set is empty
	IsNothing() bool
	// returns true when this set matches everything
	IsEverything() bool
	// returns true when the set is open / unbound and only Contains exclusions
	IsOpenSet() bool
	// returns true when the given key is within the set
	Contains(Key) bool
	// returns true when any key of the given set is within this set
	ContainsAny(KeySet) bool

	// returns true when this set Contains all keys from the given one
	SupersetOf(KeySet) bool
	// returns true when all keys of this set are contained in the given one
	SubsetOf(KeySet) bool
	// returns true when both sets have same set of keys
	Equal(KeySet) bool
	// a faster equivalent of Equal(ks.Inverse())
	EqualInverse(KeySet) bool

	// returns a set that has all keys but this set
	Inverse() KeySet
	// returns a set of keys present in at least one sets
	Union(KeySet) KeySet
	// returns a set of keys present in both sets
	Intersect(KeySet) KeySet
	// returns a set of keys present in this set and not present in the given set
	Subtract(KeySet) KeySet

	// WARNING! Do not use
	// lists keys (when IsOpenSet() == true, as then it lists _excluded_ keys)
	EnumRawKeys(func(k Key, exclusive bool) bool) bool
	// WARNING! Do not use. This must NOT be treated as a size of a set.
	// number of keys (when IsOpenSet() == true, as then it gives a number of _excluded_ keys)
	RawKeyCount() int
}

An advanced set of keys, that also represent an open set (tracks exclusions, not inclusions)

NB! An immutable inclusive/closed set MUST be able to cast to KeyList & InclusiveKeySet. An open or a mutable KeySet MUST NOT be able to cast to KeyList & InclusiveKeySet. This behavior is supported by this package.

func CopyList

func CopyList(keys KeyList) KeySet

func CopySet

func CopySet(keys KeySet) KeySet

func Everything

func Everything() KeySet

func New

func New(keys []Key) KeySet

func Nothing

func Nothing() KeySet

func SoloKeySet

func SoloKeySet(k Key) KeySet

creates an immutable set with a single key

func Wrap

func Wrap(keys KeyList) KeySet

type MutableKeySet

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

WARNING! Any KeySet(s) returned by MutableKeySet can change, unless MutableKeySet is frozen. Can't be casted to a KeyList as can be changed to be an open set.

func NewMutable

func NewMutable() MutableKeySet

Creates a new empty mutable set

func NewOpenMutable

func NewOpenMutable() MutableKeySet

Creates a new mutable open set - initial state will match any keys

func WrapAsMutable

func WrapAsMutable(keys KeyList) MutableKeySet

Creates a mutable overlay over an immutable list. The overlay will track all additions and removals. The provided KeyList must be immutable or behavior of the overlay will be incorrect.

func (*MutableKeySet) Add

func (v *MutableKeySet) Add(k Key)

add a key to this set. Repeated keys are ignored.

func (*MutableKeySet) AddAll

func (v *MutableKeySet) AddAll(ks KeySet)

adds to this set all keys from the given one. Repeated keys are ignored.

func (*MutableKeySet) AddKeys

func (v *MutableKeySet) AddKeys(keys []Key)

adds to this set all keys from the given list. Repeated keys are ignored.

func (*MutableKeySet) Copy

func (v *MutableKeySet) Copy() *MutableKeySet

creates a copy of this set

func (*MutableKeySet) Freeze

func (v *MutableKeySet) Freeze() KeySet

makes this set immutable - modification methods will panic

func (*MutableKeySet) InverseCopy

func (v *MutableKeySet) InverseCopy() *MutableKeySet

creates an complementary copy of this set

func (*MutableKeySet) IsFrozen

func (v *MutableKeySet) IsFrozen() bool

this set was made immutable - modification methods will panic

func (*MutableKeySet) Remove

func (v *MutableKeySet) Remove(k Key)

removes a key from this set. Does nothing when a key is missing.

func (*MutableKeySet) RemoveAll

func (v *MutableKeySet) RemoveAll(ks KeySet)

only keys not present in the given set will remain in this set

func (*MutableKeySet) RemoveKeys

func (v *MutableKeySet) RemoveKeys(keys []Key)

removes keys from this set. Does nothing when a key is missing.

func (*MutableKeySet) RetainAll

func (v *MutableKeySet) RetainAll(ks KeySet)

only keys present in both sets will remain in this set

Jump to

Keyboard shortcuts

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