cells

package
v0.0.0-...-36bb858 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MPL-2.0 Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply[T any](ctx context.Context, cell Cell[T], maxAttempts int, fn func(T) (T, error)) error

Apply attempts to do a CAS on the cell by applying fn to the current value to get the next value.

func CopyBytes

func CopyBytes(dst *[]byte, src []byte)

func DefaultCopy

func DefaultCopy[T any](dst *T, src T)

func DefaultEquals

func DefaultEquals[T comparable](a, b T) bool

func EqualBytes

func EqualBytes(a, b []byte) bool

func IsErrCASMaxAttempts

func IsErrCASMaxAttempts(err error) bool

func IsErrTooLarge

func IsErrTooLarge(err error) bool

func Load

func Load[T any](ctx context.Context, cell Cell[T]) (ret T, _ error)

Types

type BytesCell

type BytesCell interface {
	Cell[[]byte]
	MaxSize() int
}

BytesCell is a cell holding []byte

type BytesCellBase

type BytesCellBase struct{}

BytesCellBase provides Equals, and Copy methods. It is intended to be composed in implementations of BytesCell

func (BytesCellBase) Copy

func (BytesCellBase) Copy(dst *[]byte, src []byte)

func (BytesCellBase) Equals

func (BytesCellBase) Equals(a, b []byte) bool

type Cached

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

func NewCached

func NewCached[T any](x Cell[T]) *Cached[T]

func (*Cached[T]) CAS

func (c *Cached[T]) CAS(ctx context.Context, actual *T, prev, next T) (bool, error)

func (*Cached[T]) Copy

func (c *Cached[T]) Copy(dst *T, src T)

func (*Cached[T]) Equals

func (c *Cached[T]) Equals(a, b T) bool

func (*Cached[T]) Invalidate

func (c *Cached[T]) Invalidate()

func (*Cached[T]) Load

func (c *Cached[T]) Load(ctx context.Context, dst *T) error

type Cell

type Cell[T any] interface {
	// CAS sets the contents of the cell to next, IFF prev equals the cell contents.
	// returns whether or not the swap was successful, the actual value in the cell, or an error
	// if err != nil then success must be false.
	// the swap failing is not considered an error.
	CAS(ctx context.Context, actual *T, prev, next T) (success bool, err error)

	// Load retrieves the contents of the cell, and writes them to buf.
	// If err != nil the data returned is invalid.
	// If err == nil, n will be the number of bytes written
	Load(ctx context.Context, dst *T) error

	// Equals is the equality function used by the cell.
	Equals(a, b T) bool

	// Copy is the function used to copy values in and out of the cell.
	Copy(dst *T, src T)
}

Cell is a compare-and-swap cell

type Derived

type Derived[X, Y any] struct {
	// contains filtered or unexported fields
}

func NewDerived

func NewDerived[X, Y any](params DerivedParams[X, Y]) *Derived[X, Y]

func (*Derived[X, Y]) CAS

func (c *Derived[X, Y]) CAS(ctx context.Context, actual *Y, prev, next Y) (bool, error)

func (*Derived[X, Y]) Copy

func (c *Derived[X, Y]) Copy(dst *Y, src Y)

func (*Derived[X, Y]) Equals

func (c *Derived[X, Y]) Equals(a, b Y) bool

func (*Derived[X, Y]) Load

func (c *Derived[X, Y]) Load(ctx context.Context, dst *Y) error

type DerivedParams

type DerivedParams[X, Y any] struct {
	Inner   Cell[X]
	Forward func(ctx context.Context, dst *Y, src X) error
	Inverse func(ctx context.Context, dst *X, src Y) error
	Equals  func(Y, Y) bool
	Copy    func(*Y, Y)
}

type ErrCASMaxAttempts

type ErrCASMaxAttempts struct{}

func (ErrCASMaxAttempts) Error

func (e ErrCASMaxAttempts) Error() string

type ErrTooLarge

type ErrTooLarge struct{}

ErrTooLarge is returned from BytesCells when the object is too large to store

func (ErrTooLarge) Error

func (e ErrTooLarge) Error() string

type MemBytes

type MemBytes struct {
	*MemCell[[]byte]
	// contains filtered or unexported fields
}

func NewMemBytes

func NewMemBytes(maxSize int) *MemBytes

func (*MemBytes) MaxSize

func (mc *MemBytes) MaxSize() int

type MemCell

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

func NewMem

func NewMem[T any](eq func(T, T) bool, cp func(*T, T)) *MemCell[T]

func (*MemCell[T]) CAS

func (c *MemCell[T]) CAS(ctx context.Context, actual *T, prev, next T) (bool, error)

func (*MemCell[T]) Copy

func (c *MemCell[T]) Copy(dst *T, src T)

func (*MemCell[T]) Equals

func (c *MemCell[T]) Equals(a, b T) bool

func (*MemCell[T]) Load

func (c *MemCell[T]) Load(ctx context.Context, dst *T) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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