optimistic

package
v0.0.0-...-705c6d5 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package optimistic contains a set of "lock-free" data types that use optimistic concurrency control to allow atomic mutations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator[T any] interface {
	// Compare performs a 3-way comparison of a and b.
	Compare(a, b T) int
}

Comparator is a type that compares two values.

type LessComparator

type LessComparator[T interface{ Less(T) bool }] struct{}

LessComparator is a Comparator for types that implement a LessComparator() method.

func (LessComparator[M]) Compare

func (LessComparator[M]) Compare(a, b *uuidpb.UUID) int

Compare performs a 3-way comparison of a and b.

type OrderedComparator

type OrderedComparator[T constraints.Ordered] struct{}

OrderedComparator is a Comparator that compares values that match the constraints.OrderedComparator constraint.

func (OrderedComparator[T]) Compare

func (OrderedComparator[T]) Compare(a, b T) int

Compare performs a 3-way comparison of a and b.

type OrderedSet

type OrderedSet[M any, C Comparator[M]] struct {
	Comparator C
	// contains filtered or unexported fields
}

OrderedSet is a read-optimized lock-free ordered set.

func (*OrderedSet[M, C]) Add

func (s *OrderedSet[M, C]) Add(m M)

Add adds a member to the set.

func (*OrderedSet[M, C]) Delete

func (s *OrderedSet[M, C]) Delete(m M)

Delete removes a member from the set.

func (*OrderedSet[M, C]) Has

func (s *OrderedSet[M, C]) Has(m M) bool

Has returns true if m is a member of the set.

func (*OrderedSet[M, C]) Len

func (s *OrderedSet[M, C]) Len() int

Len returns the number of members in the set.

func (*OrderedSet[M, C]) Members

func (s *OrderedSet[M, C]) Members() []M

Members returns the members of the set, in order. The returned slice must not be modified.

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

Value is a value protected by optimistic concurrency control.

func (*Value[T]) Apply

func (v *Value[T]) Apply(
	fn func(T) (T, bool),
) (T, bool)

Apply calls fn with the current value.

If fn returns true, the value is replaced with the returned value. If the value has been replaced by another goroutine since the call to fn, the process is retried until it succeeds or fn returns false.

func (*Value[T]) Load

func (v *Value[T]) Load() T

Load returns the current value.

Jump to

Keyboard shortcuts

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