sets

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 8 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 (*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 an iterator that yeilds 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]) 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 an iterator 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 {
	Comparator C
	// contains filtered or unexported fields
}

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

func NewOrderedByComparator

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

NewOrderedByComparator returns an OrderedByComparator containing the given members.

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 an iterator that yeilds 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]) 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 an iterator 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 (*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 an iterator that yeilds 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]) 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 an iterator 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 (*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 an iterator 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]) 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 (*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 an iterator 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]) 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