sharded

package
v0.0.0-...-241c87b Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LowestMultipleOfTwo

func LowestMultipleOfTwo(backSize, n int) int

return the lowest multiple of backSize as a multiple of two which would be equal or greater than n.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter() *Counter

func (*Counter) Add

func (c *Counter) Add(delta int64)

Add adds delta to the counter's current-P shard.

func (*Counter) Get

func (c *Counter) Get() int64

Get returns the value of the current-P shard only, without merging contributions from other shards.

func (*Counter) Lock

func (*Counter) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*Counter) Total

func (c *Counter) Total() int64

Total returns the sum across all shards.

func (*Counter) Unlock

func (*Counter) Unlock()

type List

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

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func NewList

func NewList[T any]() *List[T]

NewList returns an initialized list.

func (*List[T]) Back

func (l *List[T]) Back() *element[T]

Back returns the last element of list l or nil if the list is empty.

func (*List[T]) Front

func (l *List[T]) Front() *element[T]

Front returns the first element of list l or nil if the list is empty.

func (*List[T]) Init

func (l *List[T]) Init() *List[T]

Init initializes or clears list l.

func (*List[T]) PushBack

func (l *List[T]) PushBack(v T) *element[T]

PushBack inserts a new element e with value v at the back of list l and returns e.

type Merger

type Merger[T any] interface {
	// Called by Sharded to reduce the number of shards in the pool.
	Merge(other T) T
}

Merger interface for the merge function.

type Sharded

type Sharded[T Merger[T]] struct {
	NewShard func() T
	// contains filtered or unexported fields
}

Sharded is a pool of values that are optimistically processor-local.

The zero value is ready to use. If NewShard is nil, new shards will start with the zero value of T.

func NewSharded

func NewSharded[T Merger[T]](fn func() T) *Sharded[T]

func (*Sharded[T]) Get

func (s *Sharded[T]) Get(fn func(T))

func (*Sharded[T]) GetEach

func (s *Sharded[T]) GetEach(fn func(T))

func (*Sharded) Lock

func (*Sharded) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*Sharded) Unlock

func (*Sharded) Unlock()

func (*Sharded[T]) Update

func (s *Sharded[T]) Update(fn func(T) T)

func (*Sharded[T]) UpdateEach

func (s *Sharded[T]) UpdateEach(fn func(T) T)

type Spine

type Spine struct {
	// contains filtered or unexported fields
}

func NewSpine

func NewSpine() *Spine

func (*Spine) Cap

func (s *Spine) Cap() int

func (*Spine) Get

func (s *Spine) Get(id int) *int64

func (*Spine) Grow

func (s *Spine) Grow(id int, spine *SpineArr)

func (*Spine) Lock

func (*Spine) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*Spine) Unlock

func (*Spine) Unlock()

type SpineArr

type SpineArr []atomic.Pointer[[spineBackSize]counterShard]

Jump to

Keyboard shortcuts

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