bufmap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package bufmap implements a write-only multi-reader, single-writer map of byte buffers offering wait-free reads and consistent writes. The map consists of a fixed number of slots which are assigned to keys using linear probing. Reads and writes to the data held in a slot are guarded by a seqlock.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey = errors.New("invalid key: 0")
	ErrOutOfSlots = errors.New("out of slots")
)

Functions

This section is empty.

Types

type Map

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

Map is a write-only lock free map. Its implementation is simplified by not supplying a way of deleting keys. It is also a fixed size. Keys are assigned using linear probing.

func New

func New(l, s int) *Map

New creates a Map with l buffers each consisting of s bytes

func (*Map) Get

func (m *Map) Get(k uint64, buf []byte) bool

Get atomically reads a buffer value stored against key k into buffer buf. The return value will be false if the key could not be found in the map.

func (*Map) Update

func (m *Map) Update(k uint64, fn func(data []byte, init bool) error) error

Update finds the buffer stored against key k and atomically updates it with v using the function fn. It returns the error returned by fn, if any. It will also return an error if the map is full. The function fn may be called multiple times during a single call to Update, or not called at all if the map cannot find space for the key.

Jump to

Keyboard shortcuts

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