Documentation
¶
Overview ¶
Package Set provides ordered and unordered set implementations for arbitrary comparable types.
Index ¶
- func AddCheck[T comparable](s Set[T], item T) bool
- func DeleteCheck[T comparable](s Set[T], item T) bool
- func Equal[T comparable](ctx context.Context, s1, s2 Set[T]) bool
- func PopulateSet[T comparable](ctx context.Context, set Set[T], iter fun.Iterator[T])
- type Set
- func BuildOrdered[T comparable](ctx context.Context, iter fun.Iterator[T]) Set[T]
- func BuildOrderedFromPairs[K, V comparable](pairs fun.Pairs[K, V]) Set[fun.Pair[K, V]]
- func BuildUnordered[T comparable](ctx context.Context, iter fun.Iterator[T]) Set[T]
- func BuildUnorderedFromPairs[K, V comparable](pairs fun.Pairs[K, V]) Set[fun.Pair[K, V]]
- func MakeNewOrdered[T comparable]() Set[T]
- func MakeOrdered[T comparable](size int) Set[T]
- func MakeUnordered[T comparable](len int) Set[T]
- func NewOrdered[T comparable]() Set[T]
- func NewUnordered[T comparable]() Set[T]
- func Synchronize[T comparable](s Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCheck ¶
func AddCheck[T comparable](s Set[T], item T) bool
AddCheck adds an item from a set, returning a value if that item was already in the set.
func DeleteCheck ¶
func DeleteCheck[T comparable](s Set[T], item T) bool
DeleteCheck deletes an item from a set, returning a value if that item was in the set.
func Equal ¶
func Equal[T comparable](ctx context.Context, s1, s2 Set[T]) bool
Equal tests two sets, returning true if the sets have equal values, but will return early (and false) if the context is canceled.
func PopulateSet ¶ added in v0.7.0
PopulateSet adds all elements in the iterator to the provided Set.
Types ¶
type Set ¶
type Set[T comparable] interface { // Add unconditionally adds an item to the set. Add(T) // Len Returns the number of items in the set Len() int // Delete removes an item from the set. Delete(T) // Check returns true if the item is in the set. Check(T) bool // Iterator produces an Iterator implementation for the // elements in the set. Iterator() fun.Iterator[T] }
Set describes a basic set interface, and fun provdies a straightforward implementation backed by a `map[T]struct{}`, but other implementations are possible.
func BuildOrdered ¶ added in v0.7.0
BuildOrdered creates an ordered set (new implementation) from the contents of the input iterator.
func BuildOrderedFromPairs ¶ added in v0.8.5
BuildOrderedFromPairs produces an unordered set from a sequence of pairs.
func BuildUnordered ¶ added in v0.7.0
BuildUnordered produces a new unordered set from the elements in the iterator.
func BuildUnorderedFromPairs ¶ added in v0.8.5
BuildUnorderedFromPairs produces an order-preserving set based on a sequence of Pairs.
func MakeNewOrdered ¶ added in v0.3.0
func MakeNewOrdered[T comparable]() Set[T]
MakeNewOrdered constructs a "new" ordered set implementation. This is a more simple implementation based around a linked list, with identical semantics. Items are deleted from the list synchronously--the "old" implementation does a lazy deletion that batches--and this implementation may perform more predictably for use cases that do a large number of deletions.
This implementation does not permit iteration with concurrent deletes, as is the case with the old ordered implementation.
func MakeOrdered ¶
func MakeOrdered[T comparable](size int) Set[T]
MakeOrdered produces an order-preserving set implementation, with pre-allocated capacity to the specified size. Iteration will reflect insertion order.
func MakeUnordered ¶
func MakeUnordered[T comparable](len int) Set[T]
MakeUnordered constructs a set object, pre-allocating the specified length. Iteration order is randomized.
func NewOrdered ¶
func NewOrdered[T comparable]() Set[T]
NewOrdered produces an order-preserving set implementation. Iteration order will reflect insertion order.
func NewUnordered ¶
func NewUnordered[T comparable]() Set[T]
NewUnordered constructs a set object for the given type, without prealocation.
func Synchronize ¶
func Synchronize[T comparable](s Set[T]) Set[T]
Synchronize wraps an existing set instance with a mutex. The underlying implementation provides an Unwrap method. Additionally the iterator implementation uses the adt package's synchronized iterator, which is handled specially by the `fun.IterateOne` function and a number of tools which use it.