atomicptrmap

package
v0.0.0-...-9ec6d29 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package atomicptrmap instantiates generic_atomicptrmap for testing.

Package atomicptrmap doesn't exist. This file must be instantiated using the go_template_instance rule in tools/go_generics/defs.bzl.

Index

Constants

View Source
const (
	// ShardOrder is an optional parameter specifying the base-2 log of the
	// number of shards per AtomicPtrMap. Higher values of ShardOrder reduce
	// unnecessary synchronization between unrelated concurrent operations,
	// improving performance for write-heavy workloads, but increase memory
	// usage for small maps.
	ShardOrder = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicPtrMap

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

An AtomicPtrMap maps Keys to non-nil pointers to Values. AtomicPtrMap are safe for concurrent use from multiple goroutines without additional synchronization.

The zero value of AtomicPtrMap is empty (maps all Keys to nil) and ready for use. AtomicPtrMaps must not be copied after first use.

sync.Map may be faster than AtomicPtrMap if most operations on the map are concurrent writes to a fixed set of keys. AtomicPtrMap is usually faster in other circumstances.

func (*AtomicPtrMap) CompareAndSwap

func (m *AtomicPtrMap) CompareAndSwap(key Key, oldVal, newVal *Value) *Value

CompareAndSwap checks that the Value stored for key is oldVal; if it is, it stores the Value newVal for key. CompareAndSwap returns the previous Value stored for key, whether or not it stores newVal.

func (*AtomicPtrMap) Load

func (m *AtomicPtrMap) Load(key Key) *Value

Load returns the Value stored in m for key.

func (*AtomicPtrMap) Range

func (m *AtomicPtrMap) Range(f func(key Key, val *Value) bool)

Range invokes f on each Key-Value pair stored in m. If any call to f returns false, Range stops iteration and returns.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no Key will be visited more than once, but if the Value for any Key is stored or deleted concurrently, Range may reflect any mapping for that Key from any point during the Range call.

f must not call other methods on m.

func (*AtomicPtrMap) RangeRepeatable

func (m *AtomicPtrMap) RangeRepeatable(f func(key Key, val *Value) bool)

RangeRepeatable is like Range, but:

  • RangeRepeatable may visit the same Key multiple times in the presence of concurrent mutators, possibly passing different Values to f in different calls.

  • It is safe for f to call other methods on m.

func (*AtomicPtrMap) Store

func (m *AtomicPtrMap) Store(key Key, val *Value)

Store stores the Value val for key.

func (*AtomicPtrMap) Swap

func (m *AtomicPtrMap) Swap(key Key, val *Value) *Value

Swap stores the Value val for key and returns the previously-mapped Value.

type Hasher

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

Hasher is an optional type parameter. If Hasher is provided, it must define the Init and Hash methods. One Hasher will be shared by all AtomicPtrMaps.

func (*Hasher) Hash

func (h *Hasher) Hash(key Key) uintptr

Hash returns the hash value for the given Key.

func (*Hasher) Init

func (h *Hasher) Init()

Init initializes the Hasher.

type Key

type Key struct{}

Key is a required type parameter.

type Value

type Value struct{}

Value is a required type parameter.

Jump to

Keyboard shortcuts

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