rcu

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT Imports: 2 Imported by: 0

README

(R)ead-(C)opy-update

read copy update map for golang 1.18+

How it works

This is a simple generic implementation for https://en.wikipedia.org/wiki/Read-copy-update

Inserts are slow(er) while reading is fast. We always return a read-copy of the map to the consumers, which only requires atomic access to the map at the moment of changing.

If an update to the map happens, we then update the Read Model and the next time it is requested, it will yield the updated copy.

Caveats of the Read-Copy-Update model

  • The read-copy of the model might contain outdated values. This is suitable to return to clients when they request current values
  • it is not suitable if you need the consistent underlying data. In that case a sync.Map is what you need.
  • The current read-model is shared. You should not modify data in it as this will still not be thread-safe and will modify the map for all current users.

How to get it

go get github.com/mier85/rcu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[KEY comparable, VALUE interface{}] struct {
	// contains filtered or unexported fields
}

Map is a generic thread-safe read-copy-update map

func New

func New[KEY comparable, VALUE interface{}]() Map[KEY, VALUE]

New creates a new generic RCU-map

func (*Map[KEY, VALUE]) Delete

func (m *Map[KEY, VALUE]) Delete(key KEY)

Delete deletes a value from the map

func (*Map[KEY, VALUE]) Insert

func (m *Map[KEY, VALUE]) Insert(key KEY, value VALUE)

Insert inserts a value into the map

func (*Map[KEY, VALUE]) ReadMap

func (m *Map[KEY, VALUE]) ReadMap() map[KEY]VALUE

ReadMap returns the current Read-Copy of the map

Jump to

Keyboard shortcuts

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