sets

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 7 Imported by: 8

Documentation

Overview

Package sets provides generic set data structures.

These structures are not intended for general use; they only provide the operations required by official Dogmatiq engines and utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ordered

type Ordered[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

Ordered is an ordered set of unique T values.

func NewOrdered

func NewOrdered[T cmp.Ordered](members ...T) *Ordered[T]

NewOrdered returns an Ordered containing the given members.

func NewOrderedFromKeys added in v0.16.0

func NewOrderedFromKeys[T cmp.Ordered, unused any](seq iter.Seq2[T, unused]) *Ordered[T]

NewOrderedFromKeys returns an Ordered containing the keys yielded by the given sequence.

func NewOrderedFromSeq added in v0.16.0

func NewOrderedFromSeq[T cmp.Ordered](seq iter.Seq[T]) *Ordered[T]

NewOrderedFromSeq returns an Ordered containing the values yielded by the given sequence.

func NewOrderedFromValues added in v0.16.0

func NewOrderedFromValues[T cmp.Ordered, unused any](seq iter.Seq2[unused, T]) *Ordered[T]

NewOrderedFromValues returns an Ordered containing the values yielded by the given sequence.

func (*Ordered[T]) Add

func (s *Ordered[T]) Add(members ...T)

Add adds the given members to the set.

func (*Ordered[T]) All

func (s *Ordered[T]) All() iter.Seq[T]

All returns a sequence that yields all members of the set in order.

func (*Ordered[T]) Clear

func (s *Ordered[T]) Clear()

Clear removes all members from the set.

func (*Ordered[T]) Clone

func (s *Ordered[T]) Clone() *Ordered[T]

Clone returns a shallow copy of the set.

func (*Ordered[T]) Has

func (s *Ordered[T]) Has(members ...T) bool

Has returns true if all of the given values are members of the set.

func (*Ordered[T]) Intersection added in v0.16.0

func (s *Ordered[T]) Intersection(x *Ordered[T]) *Ordered[T]

Intersection returns a set containing members that are in both s and x.

func (*Ordered[T]) IsEqual

func (s *Ordered[T]) IsEqual(x *Ordered[T]) bool

IsEqual returns true if s and x have the same members.

func (*Ordered[T]) IsStrictSubset

func (s *Ordered[T]) IsStrictSubset(x *Ordered[T]) bool

IsStrictSubset returns true if x has all of the members of s and at least one member that is not in s.

func (*Ordered[T]) IsStrictSuperset

func (s *Ordered[T]) IsStrictSuperset(x *Ordered[T]) bool

IsStrictSuperset returns true if s has all of the members of x and at least one member that is not in x.

func (*Ordered[T]) IsSubset

func (s *Ordered[T]) IsSubset(x *Ordered[T]) bool

IsSubset returns true if x has all of the members of s.

func (*Ordered[T]) IsSuperset

func (s *Ordered[T]) IsSuperset(x *Ordered[T]) bool

IsSuperset returns true if s has all of the members of x.

func (*Ordered[T]) Len

func (s *Ordered[T]) Len() int

Len returns the number of members in the set.

func (*Ordered[T]) Remove

func (s *Ordered[T]) Remove(members ...T)

Remove removes the given members from the set.

func (*Ordered[T]) Reverse

func (s *Ordered[T]) Reverse() iter.Seq[T]

Reverse returns a sequence that yields all members of the set in reverse order.

func (*Ordered[T]) Select

func (s *Ordered[T]) Select(pred func(T) bool) *Ordered[T]

Select returns the subset of s containing members for which the given predicate function returns true.

func (*Ordered[T]) Union

func (s *Ordered[T]) Union(x *Ordered[T]) *Ordered[T]

Union returns a set containing all members of s and x.

type OrderedByComparator

type OrderedByComparator[T any, C constraints.Comparator[T]] struct {
	// contains filtered or unexported fields
}

OrderedByComparator is an ordered set of unique T values where the ordering is defined by a separate comparitor type.

func NewOrderedByComparator

func NewOrderedByComparator[T any, C constraints.Comparator[T]](members ...T) *OrderedByComparator[T, C]

NewOrderedByComparator returns an OrderedByComparator containing the given members.

func NewOrderedByComparatorFromKeys added in v0.16.0

func NewOrderedByComparatorFromKeys[T any, C constraints.Comparator[T], unused any](seq iter.Seq2[T, unused]) *OrderedByComparator[T, C]

NewOrderedByComparatorFromKeys returns an OrderedByComparator containing the keys yielded by the given sequence.

func NewOrderedByComparatorFromSeq added in v0.16.0

func NewOrderedByComparatorFromSeq[T any, C constraints.Comparator[T]](seq iter.Seq[T]) *OrderedByComparator[T, C]

NewOrderedByComparatorFromSeq returns an OrderedByComparator containing the values yielded by the given sequence.

func NewOrderedByComparatorFromValues added in v0.16.0

func NewOrderedByComparatorFromValues[T any, C constraints.Comparator[T], unused any](seq iter.Seq2[unused, T]) *OrderedByComparator[T, C]

NewOrderedByComparatorFromValues returns an OrderedByComparator containing the values yielded by the given sequence.

func (*OrderedByComparator[T, C]) Add

func (s *OrderedByComparator[T, C]) Add(members ...T)

Add adds the given members to the set.

func (*OrderedByComparator[T, C]) All

func (s *OrderedByComparator[T, C]) All() iter.Seq[T]

All returns a sequence that yields all members of the set in order.

func (*OrderedByComparator[T, C]) Clear

func (s *OrderedByComparator[T, C]) Clear()

Clear removes all members from the set.

func (*OrderedByComparator[T, C]) Clone

func (s *OrderedByComparator[T, C]) Clone() *OrderedByComparator[T, C]

Clone returns a shallow copy of the set.

func (*OrderedByComparator[T, C]) Has

func (s *OrderedByComparator[T, C]) Has(members ...T) bool

Has returns true if all of the given values are members of the set.

func (*OrderedByComparator[T, C]) Intersection added in v0.16.0

func (s *OrderedByComparator[T, C]) Intersection(x *OrderedByComparator[T, C]) *OrderedByComparator[T, C]

Intersection returns a set containing members that are in both s and x.

func (*OrderedByComparator[T, C]) IsEqual

func (s *OrderedByComparator[T, C]) IsEqual(x *OrderedByComparator[T, C]) bool

IsEqual returns true if s and x have the same members.

func (*OrderedByComparator[T, C]) IsStrictSubset

func (s *OrderedByComparator[T, C]) IsStrictSubset(x *OrderedByComparator[T, C]) bool

IsStrictSubset returns true if x has all of the members of s and at least one member that is not in s.

func (*OrderedByComparator[T, C]) IsStrictSuperset

func (s *OrderedByComparator[T, C]) IsStrictSuperset(x *OrderedByComparator[T, C]) bool

IsStrictSuperset returns true if s has all of the members of x and at least one member that is not in x.

func (*OrderedByComparator[T, C]) IsSubset

func (s *OrderedByComparator[T, C]) IsSubset(x *OrderedByComparator[T, C]) bool

IsSubset returns true if x has all of the members of s.

func (*OrderedByComparator[T, C]) IsSuperset

func (s *OrderedByComparator[T, C]) IsSuperset(x *OrderedByComparator[T, C]) bool

IsSuperset returns true if s has all of the members of x.

func (*OrderedByComparator[T, C]) Len

func (s *OrderedByComparator[T, C]) Len() int

Len returns the number of members in the set.

func (*OrderedByComparator[T, C]) Remove

func (s *OrderedByComparator[T, C]) Remove(members ...T)

Remove removes the given members from the set.

func (*OrderedByComparator[T, C]) Reverse

func (s *OrderedByComparator[T, C]) Reverse() iter.Seq[T]

Reverse returns a sequence that yields all members of the set in reverse order.

func (*OrderedByComparator[T, C]) Select

func (s *OrderedByComparator[T, C]) Select(pred func(T) bool) *OrderedByComparator[T, C]

Select returns the subset of s containing members for which the given predicate function returns true.

func (*OrderedByComparator[T, C]) Union

func (s *OrderedByComparator[T, C]) Union(x *OrderedByComparator[T, C]) *OrderedByComparator[T, C]

Union returns a set containing all members of s and x.

type OrderedByMember

type OrderedByMember[T constraints.Ordered[T]] struct {
	// contains filtered or unexported fields
}

OrderedByMember is an ordered set of unique T values with the order defined by the T.Compare method.

func NewOrderedByMember

func NewOrderedByMember[T constraints.Ordered[T]](members ...T) *OrderedByMember[T]

NewOrderedByMember returns an OrderedByMember containing the given members.

func NewOrderedByMemberFromKeys added in v0.16.0

func NewOrderedByMemberFromKeys[T constraints.Ordered[T], unused any](seq iter.Seq2[T, unused]) *OrderedByMember[T]

NewOrderedByMemberFromKeys returns an OrderedByMember containing the keys yielded by the given sequence.

func NewOrderedByMemberFromSeq added in v0.16.0

func NewOrderedByMemberFromSeq[T constraints.Ordered[T]](seq iter.Seq[T]) *OrderedByMember[T]

NewOrderedByMemberFromSeq returns an OrderedByMember containing the values yielded by the given sequence.

func NewOrderedByMemberFromValues added in v0.16.0

func NewOrderedByMemberFromValues[T constraints.Ordered[T], unused any](seq iter.Seq2[unused, T]) *OrderedByMember[T]

NewOrderedByMemberFromValues returns an OrderedByMember containing the values yielded by the given sequence.

func (*OrderedByMember[T]) Add

func (s *OrderedByMember[T]) Add(members ...T)

Add adds the given members to the set.

func (*OrderedByMember[T]) All

func (s *OrderedByMember[T]) All() iter.Seq[T]

All returns a sequence that yields all members of the set in order.

func (*OrderedByMember[T]) Clear

func (s *OrderedByMember[T]) Clear()

Clear removes all members from the set.

func (*OrderedByMember[T]) Clone

func (s *OrderedByMember[T]) Clone() *OrderedByMember[T]

Clone returns a shallow copy of the set.

func (*OrderedByMember[T]) Has

func (s *OrderedByMember[T]) Has(members ...T) bool

Has returns true if all of the given values are members of the set.

func (*OrderedByMember[T]) Intersection added in v0.16.0

func (s *OrderedByMember[T]) Intersection(x *OrderedByMember[T]) *OrderedByMember[T]

Intersection returns a set containing members that are in both s and x.

func (*OrderedByMember[T]) IsEqual

func (s *OrderedByMember[T]) IsEqual(x *OrderedByMember[T]) bool

IsEqual returns true if s and x have the same members.

func (*OrderedByMember[T]) IsStrictSubset

func (s *OrderedByMember[T]) IsStrictSubset(x *OrderedByMember[T]) bool

IsStrictSubset returns true if x has all of the members of s and at least one member that is not in s.

func (*OrderedByMember[T]) IsStrictSuperset

func (s *OrderedByMember[T]) IsStrictSuperset(x *OrderedByMember[T]) bool

IsStrictSuperset returns true if s has all of the members of x and at least one member that is not in x.

func (*OrderedByMember[T]) IsSubset

func (s *OrderedByMember[T]) IsSubset(x *OrderedByMember[T]) bool

IsSubset returns true if x has all of the members of s.

func (*OrderedByMember[T]) IsSuperset

func (s *OrderedByMember[T]) IsSuperset(x *OrderedByMember[T]) bool

IsSuperset returns true if s has all of the members of x.

func (*OrderedByMember[T]) Len

func (s *OrderedByMember[T]) Len() int

Len returns the number of members in the set.

func (*OrderedByMember[T]) Remove

func (s *OrderedByMember[T]) Remove(members ...T)

Remove removes the given members from the set.

func (*OrderedByMember[T]) Reverse

func (s *OrderedByMember[T]) Reverse() iter.Seq[T]

Reverse returns a sequence that yields all members of the set in reverse order.

func (*OrderedByMember[T]) Select

func (s *OrderedByMember[T]) Select(pred func(T) bool) *OrderedByMember[T]

Select returns the subset of s containing members for which the given predicate function returns true.

func (*OrderedByMember[T]) Union

func (s *OrderedByMember[T]) Union(x *OrderedByMember[T]) *OrderedByMember[T]

Union returns a set containing all members of s and x.

type Proto

type Proto[T proto.Message] struct {
	// contains filtered or unexported fields
}

Proto is an unordered set of unique Protocol Buffers messages of type T.

T must be a pointer type that implements proto.Message.

Equality is determined based on the serialized form of the message, and so is subject to the caveats described by https://protobuf.dev/programming-guides/encoding/#implications.

At time of writing, the Go implementation provides deterministic output for the same input within the same binary/process, which is sufficient for the purposes of this type.

func NewProto

func NewProto[T proto.Message](members ...T) *Proto[T]

NewProto returns a Proto containing the given members.

func NewProtoFromKeys added in v0.16.0

func NewProtoFromKeys[T proto.Message, unused any](seq iter.Seq2[T, unused]) *Proto[T]

NewProtoFromKeys returns a Proto containing the keys yielded by the given sequence.

func NewProtoFromSeq added in v0.16.0

func NewProtoFromSeq[T proto.Message](seq iter.Seq[T]) *Proto[T]

NewProtoFromSeq returns a Proto containing the values yielded by the given sequence.

func NewProtoFromValues added in v0.16.0

func NewProtoFromValues[T proto.Message, unused any](seq iter.Seq2[unused, T]) *Proto[T]

NewProtoFromValues returns a Proto containing the values yielded by the given sequence.

func (*Proto[T]) Add

func (s *Proto[T]) Add(members ...T)

Add adds the given members to the set.

func (*Proto[T]) All

func (s *Proto[T]) All() iter.Seq[T]

All returns a sequence that yields all members of the set in no particular order.

func (*Proto[T]) Clear

func (s *Proto[T]) Clear()

Clear removes all members from the set.

func (*Proto[T]) Clone

func (s *Proto[T]) Clone() *Proto[T]

Clone returns a shallow copy of the set.

func (*Proto[T]) Has

func (s *Proto[T]) Has(members ...T) bool

Has returns true if all of the given values are members of the set.

func (*Proto[T]) Intersection added in v0.16.0

func (s *Proto[T]) Intersection(x *Proto[T]) *Proto[T]

Intersection returns a set containing members that are in both s and x.

func (*Proto[T]) IsEqual

func (s *Proto[T]) IsEqual(x *Proto[T]) bool

IsEqual returns true if s and x have the same members.

func (*Proto[T]) IsStrictSubset

func (s *Proto[T]) IsStrictSubset(x *Proto[T]) bool

IsStrictSubset returns true if x has all of the members of s and at least one member that is not in s.

func (*Proto[T]) IsStrictSuperset

func (s *Proto[T]) IsStrictSuperset(x *Proto[T]) bool

IsStrictSuperset returns true if s has all of the members of x and at least one member that is not in x.

func (*Proto[T]) IsSubset

func (s *Proto[T]) IsSubset(x *Proto[T]) bool

IsSubset returns true if x has all of the members of s.

func (*Proto[T]) IsSuperset

func (s *Proto[T]) IsSuperset(x *Proto[T]) bool

IsSuperset returns true if s has all of the members of x.

func (*Proto[T]) Len

func (s *Proto[T]) Len() int

Len returns the number of members in the set.

func (*Proto[T]) Remove

func (s *Proto[T]) Remove(members ...T)

Remove removes the given members from the set.

func (*Proto[T]) Select

func (s *Proto[T]) Select(pred func(T) bool) *Proto[T]

Select returns the subset of s containing members for which the given predicate function returns true.

func (*Proto[T]) Union

func (s *Proto[T]) Union(x *Proto[T]) *Proto[T]

Union returns a set containing all members of s and x.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is an unordered set of unique T values.

func New

func New[T comparable](members ...T) *Set[T]

New returns a Set containing the given members.

func NewFromKeys added in v0.16.0

func NewFromKeys[K comparable, unused any](seq iter.Seq2[K, unused]) *Set[K]

NewFromKeys returns a Set containing the keys yielded by the given sequence.

func NewFromSeq added in v0.16.0

func NewFromSeq[T comparable](seq iter.Seq[T]) *Set[T]

NewFromSeq returns a Set containing the values yielded by the given sequence.

func NewFromValues added in v0.16.0

func NewFromValues[T comparable, unused any](seq iter.Seq2[unused, T]) *Set[T]

NewFromValues returns a Set containing the values yielded by the given sequence.

func (*Set[T]) Add

func (s *Set[T]) Add(members ...T)

Add adds the given members to the set.

func (*Set[T]) All

func (s *Set[T]) All() iter.Seq[T]

All returns a sequence that yields all members of the set in no particular order.

func (*Set[T]) Clear

func (s *Set[T]) Clear()

Clear removes all members from the set.

func (*Set[T]) Clone

func (s *Set[T]) Clone() *Set[T]

Clone returns a shallow copy of the set.

func (*Set[T]) Has

func (s *Set[T]) Has(members ...T) bool

Has returns true if all of the given values are members of the set.

func (*Set[T]) Intersection added in v0.16.0

func (s *Set[T]) Intersection(x *Set[T]) *Set[T]

Intersection returns a set containing members that are in both s and x.

func (*Set[T]) IsEqual

func (s *Set[T]) IsEqual(x *Set[T]) bool

IsEqual returns true if s and x have the same members.

func (*Set[T]) IsStrictSubset

func (s *Set[T]) IsStrictSubset(x *Set[T]) bool

IsStrictSubset returns true if x has all of the members of s and at least one member that is not in s.

func (*Set[T]) IsStrictSuperset

func (s *Set[T]) IsStrictSuperset(x *Set[T]) bool

IsStrictSuperset returns true if s has all of the members of x and at least one member that is not in x.

func (*Set[T]) IsSubset

func (s *Set[T]) IsSubset(x *Set[T]) bool

IsSubset returns true if x has all of the members of s.

func (*Set[T]) IsSuperset

func (s *Set[T]) IsSuperset(x *Set[T]) bool

IsSuperset returns true if s has all of the members of x.

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len returns the number of members in the set.

func (*Set[T]) Remove

func (s *Set[T]) Remove(members ...T)

Remove removes the given members from the set.

func (*Set[T]) Select

func (s *Set[T]) Select(pred func(T) bool) *Set[T]

Select returns the subset of s containing members for which the given predicate function returns true.

func (*Set[T]) Union

func (s *Set[T]) Union(x *Set[T]) *Set[T]

Union returns a set containing all members of s and x.

Jump to

Keyboard shortcuts

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