Documentation
¶
Overview ¶
Package set provides an abstraction of a persisted set data type.
Index ¶
- func RunBenchmarks(b *testing.B, store BinaryStore)
- func RunTests(t *testing.T, store BinaryStore)
- type BinaryInterceptor
- type BinaryRangeFunc
- type BinarySet
- type BinaryStore
- type Interceptor
- func (i *Interceptor[T]) AfterAdd(fn func(set string, v T) error)
- func (i *Interceptor[T]) AfterRemove(fn func(set string, v T) error)
- func (i *Interceptor[T]) BeforeAdd(fn func(set string, v T) error)
- func (i *Interceptor[T]) BeforeOpen(fn func(name string) error)
- func (i *Interceptor[T]) BeforeRemove(fn func(set string, v T) error)
- type RangeFunc
- type Set
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunBenchmarks ¶
func RunBenchmarks( b *testing.B, store BinaryStore, )
RunBenchmarks runs benchmarks against a BinaryStore implementation.
func RunTests ¶
func RunTests( t *testing.T, store BinaryStore, )
RunTests runs tests that confirm a BinaryStore implementation behaves correctly.
Types ¶
type BinaryInterceptor ¶ added in v0.13.0
type BinaryInterceptor = Interceptor[[]byte]
BinaryInterceptor is an Interceptor that can be used to intercept operations on a BinarySet.
type BinaryRangeFunc ¶ added in v0.12.0
A BinaryRangeFunc is a function used to range over members of a BinarySet.
If err is non-nil, ranging stops and err is propagated up the stack. Otherwise, if ok is false, ranging stops without any error being propagated.
type BinarySet ¶
A BinarySet is a unique set of binary values.
Values in a binary set cannot be an empty slice.
type BinaryStore ¶
BinaryStore is a collection of sets that track membership of opaque binary values.
func WithTelemetry ¶
func WithTelemetry( s BinaryStore, p trace.TracerProvider, m metric.MeterProvider, l log.LoggerProvider, ) BinaryStore
WithTelemetry returns a BinaryStore that adds telemetry to s.
type Interceptor ¶ added in v0.13.0
type Interceptor[T any] struct { // contains filtered or unexported fields }
Interceptor defines functions that are invoked around set operations.
func (*Interceptor[T]) AfterAdd ¶ added in v0.13.0
func (i *Interceptor[T]) AfterAdd(fn func(set string, v T) error)
AfterAdd sets the function that is invoked after a member is added to the Set.
func (*Interceptor[T]) AfterRemove ¶ added in v0.13.0
func (i *Interceptor[T]) AfterRemove(fn func(set string, v T) error)
AfterRemove sets the function that is invoked after a member is removed from the Set.
func (*Interceptor[T]) BeforeAdd ¶ added in v0.13.0
func (i *Interceptor[T]) BeforeAdd(fn func(set string, v T) error)
BeforeAdd sets the function that is invoked before a member is added to the Set.
func (*Interceptor[T]) BeforeOpen ¶ added in v0.13.0
func (i *Interceptor[T]) BeforeOpen(fn func(name string) error)
BeforeOpen sets the function that is invoked before a Set is opened.
func (*Interceptor[T]) BeforeRemove ¶ added in v0.13.0
func (i *Interceptor[T]) BeforeRemove(fn func(set string, v T) error)
BeforeRemove sets the function that is invoked before a member is removed from the Set.
type RangeFunc ¶ added in v0.12.0
A RangeFunc is a function used to range over the members of a Set.
If err is non-nil, ranging stops and err is propagated up the stack. Otherwise, if ok is false, ranging stops without any error being propagated.
type Set ¶
type Set[T any] interface { // Name returns the name of the set. Name() string // Has returns true if v is a member of the set. Has(ctx context.Context, v T) (bool, error) // Add ensures v is a member of the set. Add(ctx context.Context, v T) error // TryAdd ensures v is a member of the set. It returns true if v was added, // or false if it was already a member. // // Add() may be more performant when knowledge of v's prior membership is // not required. TryAdd(ctx context.Context, v T) (bool, error) // Remove ensures v is not a member of the set. Remove(ctx context.Context, v T) error // TryRemove ensures v is not a member of the set. It returns true if v was // removed, or false if it was not a member. // // Remove() may be more performant when knowledge of v's prior membership is // not required. TryRemove(ctx context.Context, v T) (bool, error) // Range invokes fn for each member of the set in an undefined order. Range(ctx context.Context, fn RangeFunc[T]) error // Close closes the set. Close() error }
Set is a unique set of values of type T.
type Store ¶
type Store[T any] interface { // Open returns the set with the given name. Open(ctx context.Context, name string) (Set[T], error) }
Store is a collection of sets that track membership of values of type T.
func NewMarshalingStore ¶ added in v0.10.2
func NewMarshalingStore[T any]( s BinaryStore, m marshaler.Marshaler[T], ) Store[T]
NewMarshalingStore returns a new Store that marshals/unmarshals values of type T to/from an underlying BinaryStore.
func WithInterceptor ¶ added in v0.13.0
func WithInterceptor[T any](s Store[T], in *Interceptor[T]) Store[T]
WithInterceptor returns a Store that invokes the functions defined by the given Interceptor when performing operations on s.