Documentation ¶
Overview ¶
Package frozen provides immutable data structures.
Index ¶
- func MapToGoMap[K comparable, V any](m Map[K, V]) map[K]V
- type BitIterator
- type IntSet
- func (s IntSet[I]) Any() I
- func (s IntSet[I]) Count() int
- func (s IntSet[I]) Elements() []I
- func (s IntSet[I]) Equal(t IntSet[I]) bool
- func (s IntSet[I]) EqualSet(t IntSet[I]) bool
- func (s IntSet[I]) Format(f fmt.State, verb rune)
- func (s IntSet[I]) Has(val I) bool
- func (s IntSet[I]) Hash(seed uintptr) uintptr
- func (s IntSet[I]) Intersection(t IntSet[I]) IntSet[I]
- func (s IntSet[I]) IsEmpty() bool
- func (s IntSet[I]) IsSubsetOf(t IntSet[I]) bool
- func (s IntSet[I]) Map(f func(elem I) I) IntSet[I]
- func (s IntSet[I]) Range() Iterator[I]
- func (s IntSet[I]) Same(t any) bool
- func (s IntSet[I]) String() string
- func (s IntSet[I]) Union(t IntSet[I]) IntSet[I]
- func (s IntSet[I]) Where(pred func(elem I) bool) IntSet[I]
- func (s IntSet[I]) With(i I) IntSet[I]
- func (s IntSet[I]) Without(i I) IntSet[I]
- type Iterator
- type Key
- type KeyValue
- type Map
- func MapMap[K, V, U any](m Map[K, V], f func(key K, val V) U) Map[K, U]
- func NewMap[K any, V any](kvs ...KeyValue[K, V]) Map[K, V]
- func NewMapFromGoMap[K comparable, V any](m map[K]V) Map[K, V]
- func NewMapFromKeys[K any, V any](keys Set[K], f func(key K) V) Map[K, V]
- func SetGroupBy[T, K any](s Set[T], key func(el T) K) Map[K, Set[T]]
- func (m Map[K, V]) Any() (key K, value V)
- func (m Map[K, V]) Count() int
- func (m Map[K, V]) DebugReport(debug.Tag) string
- func (m Map[K, V]) EqArgs() *tree.EqArgs[mapEntry[K, V]]
- func (m Map[K, V]) EqKeyArgs() *tree.EqArgs[mapEntry[K, V]]
- func (m Map[K, V]) Equal(n Map[K, V]) bool
- func (m Map[K, V]) Format(f fmt.State, verb rune)
- func (m Map[K, V]) Get(key K) (_ V, _ bool)
- func (m Map[K, V]) GetElse(key K, deflt V) V
- func (m Map[K, V]) GetElseFunc(key K, deflt func() V) V
- func (m Map[K, V]) Has(key K) bool
- func (m Map[K, V]) Hash(seed uintptr) uintptr
- func (m Map[K, V]) IsEmpty() bool
- func (m Map[K, V]) Keys() Set[K]
- func (m Map[K, V]) MarshalJSON() ([]byte, error)
- func (m Map[K, V]) Merge(n Map[K, V], resolve func(key K, a, b V) V) Map[K, V]
- func (m Map[K, V]) MustGet(key K) V
- func (m Map[K, V]) Project(keys ...K) Map[K, V]
- func (m Map[K, V]) Range() MapIterator[K, V]
- func (m Map[K, V]) Same(a any) bool
- func (m Map[K, V]) String() string
- func (m Map[K, V]) Update(n Map[K, V]) Map[K, V]
- func (m Map[K, V]) Values() Set[V]
- func (m Map[K, V]) Where(pred func(key K, val V) bool) Map[K, V]
- func (m Map[K, V]) With(key K, val V) Map[K, V]
- func (m Map[K, V]) Without(key K) Map[K, V]
- type MapBuilder
- type MapIterator
- type Set
- func Intersection[T any](sets ...Set[T]) Set[T]
- func Iota[T ~int](stop T) Set[T]
- func Iota2[T ~int](start, stop T) Set[T]
- func Iota3[T ~int](start, stop, step T) Set[T]
- func NewSet[T any](values ...T) Set[T]
- func NewSetFromMask64(mask uint64) Set[int]
- func Powerset[T any](s Set[T]) Set[Set[T]]
- func SetAs[U, T any](s Set[T]) Set[U]
- func SetMap[T, U any](s Set[T], f func(elem T) U) Set[U]
- func Union[T any](sets ...Set[T]) Set[T]
- func (s Set[T]) Any() T
- func (s Set[T]) AnyN(n int) Set[T]
- func (s Set[T]) AsSetAny() Set[any]
- func (s Set[T]) Count() int
- func (s Set[T]) Difference(t Set[T]) Set[T]
- func (s Set[T]) Elements() []T
- func (s Set[T]) Equal(t Set[T]) bool
- func (s Set[T]) First(less tree.Less[T]) any
- func (s Set[T]) FirstN(n int, less tree.Less[T]) Set[T]
- func (s Set[T]) Format(f fmt.State, verb rune)
- func (s Set[T]) Has(val T) bool
- func (s Set[T]) Hash(seed uintptr) uintptr
- func (s Set[T]) Intersection(t Set[T]) Set[T]
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) IsSubsetOf(t Set[T]) bool
- func (s Set[T]) MarshalJSON() ([]byte, error)
- func (s Set[T]) OrderedElements(less tree.Less[T]) []T
- func (s Set[T]) OrderedFirstN(n int, less tree.Less[T]) []T
- func (s Set[T]) OrderedRange(less tree.Less[T]) Iterator[T]
- func (s Set[T]) Range() Iterator[T]
- func (s Set[T]) Reduce(reduce func(elems ...T) T) (T, bool)
- func (s Set[T]) Reduce2(reduce func(a, b T) T) (T, bool)
- func (s Set[T]) Same(a any) bool
- func (s Set[T]) String() string
- func (s Set[T]) SymmetricDifference(t Set[T]) Set[T]
- func (s Set[T]) Union(t Set[T]) Set[T]
- func (s Set[T]) Where(pred func(elem T) bool) Set[T]
- func (s Set[T]) With(v T) Set[T]
- func (s Set[T]) Without(v T) Set[T]
- type SetBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapToGoMap ¶ added in v1.5.0
func MapToGoMap[K comparable, V any](m Map[K, V]) map[K]V
MapToGoMap transforms a Map[K, V] to a map[K]V. K must be comparable.
Types ¶
type BitIterator ¶
type BitIterator uintptr
BitIterator represents a set of one-bits and the ability to enumerate them.
func (BitIterator) Count ¶
func (b BitIterator) Count() int
func (BitIterator) Has ¶
func (b BitIterator) Has(i int) bool
func (BitIterator) Index ¶
func (b BitIterator) Index() int
func (BitIterator) Next ¶
func (b BitIterator) Next() BitIterator
func (BitIterator) String ¶
func (b BitIterator) String() string
func (BitIterator) With ¶
func (b BitIterator) With(i int) BitIterator
func (BitIterator) Without ¶
func (b BitIterator) Without(i int) BitIterator
type IntSet ¶
type IntSet[I integer] struct {
// contains filtered or unexported fields
}
func NewIntSet ¶
func NewIntSet[I integer](is ...I) IntSet[I]
NewIntSet returns an IntSet with the values provided.
func (IntSet[I]) Elements ¶
func (s IntSet[I]) Elements() []I
Elements returns all the values of IntSet.
func (IntSet[I]) Intersection ¶
Intersection returns an IntSet whose values exists in s and t.
func (IntSet[I]) IsSubsetOf ¶
IsSubsetOf returns true if s is a subset of t and false otherwise.
type KeyValue ¶
type KeyValue[K, V any] struct { Key K Value V }
KeyValue[K, V] represents a key-value pair for insertion into a Map.
func (KeyValue[K, V]) Format ¶ added in v0.21.0
String returns a string representation of a KeyValue[K, V].
type Map ¶
Map maps keys to values. The zero value is the empty Map.
func MapMap ¶ added in v0.21.0
Map returns a Map with keys from this Map, but the values replaced by the result of calling f.
func NewMapFromGoMap ¶
func NewMapFromGoMap[K comparable, V any](m map[K]V) Map[K, V]
NewMapFromGoMap takes a map[K]V and returns a frozen Map from it.
func NewMapFromKeys ¶
NewMapFromKeys creates a new Map in which values are computed from keys.
func SetGroupBy ¶ added in v0.21.0
GroupBy returns a Map that groups elements in the Set by their key.
func (Map[K, V]) Any ¶
func (m Map[K, V]) Any() (key K, value V)
Any returns an arbitrary entry from the Map.
func (Map[K, V]) DebugReport ¶ added in v0.20.0
DebugReport is for internal use.
func (Map[K, V]) Equal ¶
Equal returns true iff i is a Map with all the same key-value pairs as this Map.
func (Map[K, V]) Get ¶
Get returns the value associated with key in m and true iff the key is found.
func (Map[K, V]) GetElse ¶
func (m Map[K, V]) GetElse(key K, deflt V) V
GetElse returns the value associated with key in m or deflt if the key is not found.
func (Map[K, V]) GetElseFunc ¶
func (m Map[K, V]) GetElseFunc(key K, deflt func() V) V
GetElseFunc returns the value associated with key in m or the result of calling deflt if the key is not found.
func (Map[K, V]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Map[K, V]) Merge ¶
Merge returns a map from the merging between two maps, should there be a key overlap, the value that corresponds to key will be replaced by the value resulted from the provided resolve function.
func (Map[K, V]) MustGet ¶
func (m Map[K, V]) MustGet(key K) V
MustGet returns the value associated with key in m or panics if the key is not found.
func (Map[K, V]) Range ¶
func (m Map[K, V]) Range() MapIterator[K, V]
Range returns a MapIterator over the Map.
func (Map[K, V]) Same ¶ added in v0.21.0
Same returns true iff a is a Map and m and n have all the same key-values.
func (Map[K, V]) Update ¶
Update returns a Map with key-value pairs from n added or replacing existing keys.
type MapBuilder ¶
MapBuilder[K, V] provides a more efficient way to build Maps incrementally.
func NewMapBuilder ¶
func NewMapBuilder[K any, V any](capacity int) *MapBuilder[K, V]
func (*MapBuilder[K, V]) Count ¶
func (b *MapBuilder[K, V]) Count() int
Count returns the number of entries in the Map under construction.
func (*MapBuilder[K, V]) Finish ¶
func (b *MapBuilder[K, V]) Finish() Map[K, V]
Finish returns a Map containing all entries added since the MapBuilder[K, V] was initialised or the last call to Finish.
func (*MapBuilder[K, V]) Get ¶
func (b *MapBuilder[K, V]) Get(key K) (V, bool)
Get returns the value for key from the Map under construction or false if not found.
func (*MapBuilder[K, V]) Has ¶ added in v0.20.0
func (b *MapBuilder[K, V]) Has(key K) bool
func (*MapBuilder[K, V]) Put ¶
func (b *MapBuilder[K, V]) Put(key K, value V)
Put adds or changes an entry into the Map under construction.
func (*MapBuilder[K, V]) Remove ¶
func (b *MapBuilder[K, V]) Remove(key K)
Remove removes an entry from the Map under construction.
type MapIterator ¶
MapIterator provides for iterating over a Map.
func (*MapIterator[K, V]) Entry ¶
func (i *MapIterator[K, V]) Entry() (key K, value V)
Entry returns the current key-value pair as two return values.
func (*MapIterator[K, V]) Key ¶
func (i *MapIterator[K, V]) Key() K
Key returns the key for the current entry.
func (*MapIterator[K, V]) Next ¶
func (i *MapIterator[K, V]) Next() bool
Next moves to the next key-value pair or returns false if there are no more.
func (*MapIterator[K, V]) Value ¶
func (i *MapIterator[K, V]) Value() V
Value returns the value for the current entry.
type Set ¶
type Set[T any] struct { // contains filtered or unexported fields }
Set holds a set of values of type T. The zero value is the empty Set.
func Intersection ¶
Intersection returns the n-ary intersection of a Set of Sets.
func Iota3 ¶
Iota3 returns a Set with elements {start, start+step, start+2*step, ...} up to but not including stop. Negative steps are allowed.
func NewSetFromMask64 ¶
NewSetFromMask64 returns a Set containing all elements 2**i such that bit i of mask is set.
func SetMap ¶ added in v0.21.0
// Map returns a Set with all the results of applying f to all elements in s.
func (Set[T]) Difference ¶
Difference returns a Set with all elements that are s but not in t.
func (Set[T]) Intersection ¶
Intersection returns a Set with all elements that are in both s and t.
func (Set[T]) IsSubsetOf ¶
IsSubsetOf returns true iff no element in s is not in t.
func (Set[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Set[T]) OrderedElements ¶
OrderedElements takes elements in a defined order.
func (Set[T]) OrderedFirstN ¶
OrderedFirstN returns a list of elements in a defined order.
func (Set[T]) OrderedRange ¶
OrderedRange returns a SetIterator for the Set that iterates over the elements in a specified order.
func (Set[T]) Reduce ¶
Reduce returns the result of applying reduce to the elements of s or false if s.IsEmpty(). The result of each call is used as the acc argument for the next element.
The reduce function must have the following properties:
- commutative: reduce(a, b, c) == reduce(c, a, b)
- associative: reduce(reduce(a, b), c) == reduce(a, reduce(b, c))
By implication, reduce must accept its own output as input.
elems will never be empty.
func (Set[T]) Reduce2 ¶
Reduce2 is a convenience wrapper for `Reduce`, allowing the caller to implement a simpler, albeit less efficient, binary `reduce` function instead of an n-adic one.
func (Set[T]) Same ¶ added in v0.21.0
Same returns true iff a is a Set and s and a have all the same elements.
func (Set[T]) SymmetricDifference ¶
SymmetricDifference returns a Set with all elements that are s or t, but not both.
type SetBuilder ¶
type SetBuilder[T any] struct { // contains filtered or unexported fields }
SetBuilder[T] provides a more efficient way to build sets incrementally.
func NewSetBuilder ¶
func NewSetBuilder[T any](capacity int) *SetBuilder[T]
func (*SetBuilder[T]) Add ¶
func (b *SetBuilder[T]) Add(v T)
Add adds el to the Set under construction.
func (*SetBuilder[T]) Count ¶
func (b *SetBuilder[T]) Count() int
Count returns the count of the Set that will be returned from Finish().
func (*SetBuilder[T]) Finish ¶
func (b *SetBuilder[T]) Finish() Set[T]
Finish returns a Set containing all elements added since the SetBuilder[T] was initialised or the last call to Finish.
func (SetBuilder[T]) Format ¶ added in v0.20.0
func (b SetBuilder[T]) Format(f fmt.State, verb rune)
func (*SetBuilder[T]) Has ¶
func (b *SetBuilder[T]) Has(v T) bool
func (*SetBuilder[T]) Remove ¶
func (b *SetBuilder[T]) Remove(v T)
Remove removes el to the Set under construction.
func (SetBuilder[T]) String ¶ added in v0.20.0
func (b SetBuilder[T]) String() string