sync

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: BSD-3-Clause Imports: 5 Imported by: 12

Documentation

Overview

Package sync provides synchronization primitives similar to the sync package of Go's standard library, however here with a focus on parallel performance rather than concurrency. So far, this package only provides support for a parallel map that can be used to some extent as a drop-in replacement for the concurrent map of the standard library. For other synchronization primitivies, such as condition variables, mutual exclusion locks, object pools, or atomic memory primitives, please use the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hasher

type Hasher interface {
	Hash() uint64
}

A Hasher represents an object that has a hash value, which is needed by Map.

If Go would allow access to the predefined hash functions for Go types, this interface would not be needed.

type Map

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

A Map is a parallel map that consists of several split maps that can be individually locked and accessed.

The zero Map is not valid.

func NewMap

func NewMap(size int) *Map

NewMap returns a map with size splits.

If size is <= 0, runtime.GOMAXPROCS(0) is used instead.

func (*Map) And

func (m *Map) And(predicate func(map[interface{}]interface{}) bool) bool

And calls predicate for every split of m sequentially. If any predicate invocation returns false, And immediately terminates and also returns false. Otherwise, And returns true.

While predicate is executed on a split of m, And holds the corresponding lock.

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

func (*Map) Delete

func (m *Map) Delete(key Hasher)

Delete deletes the value for a key.

func (*Map) DeleteOrCompute

func (m *Map) DeleteOrCompute(key Hasher, computer func() interface{}) (actual interface{}, deleted bool)

DeleteOrCompute deletes and returns the existing value for the key if present. Otherwise, it calls computer, and then stores and returns the computed value. The deleted result is true if the value was deleted, false if stored.

The computer function is invoked either zero times or once. While computer is executing, a lock is being held on a portion of the map, so the function should be brief.

func (*Map) DeleteOrStore

func (m *Map) DeleteOrStore(key Hasher, value interface{}) (actual interface{}, deleted bool)

DeleteOrStore deletes and returns the existing value for the key if present. Otherwise, it stores and returns the given value. The deleted result is true if the value was deleted, false if stored.

func (*Map) Load

func (m *Map) Load(key Hasher) (value interface{}, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*Map) LoadOrCompute

func (m *Map) LoadOrCompute(key Hasher, computer func() interface{}) (actual interface{}, loaded bool)

LoadOrCompute returns the existing value for the key if present. Otherwise, it calls computer, and then stores and returns the computed value. The loaded result is true if the value was loaded, false if stored.

The computer function is invoked either zero times or once. While computer is executing no locks related to this map are being held.

The computed value may not be stored and returned, since a parallel thread may have successfully stored a value for the key in the meantime. In that case, the value stored by the parallel thread is returned instead.

func (*Map) LoadOrStore

func (m *Map) LoadOrStore(key Hasher, value interface{}) (actual interface{}, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*Map) Modify

func (m *Map) Modify(
	key Hasher,
	modifier func(value interface{}, ok bool) (replacement interface{}, storeNotDelete bool),
) (replacement interface{}, storeNotDelete bool)

Modify looks up a value for the key if present and passes it to the modifier. The ok parameter indicates whether value was found in the map. The replacement returned by the modifier is then stored as a value for key in the map if storeNotDelete is true, otherwise the value is deleted from the map. Modify returns the same results as modifier.

The modifier is invoked exactly once. While modifier is executing, a lock is being held on a portion of the map, so the function should be brief.

This is the most general modification function for parallel maps. Other functions that modify the map are potentially more efficient, so it is better to be more specific if possible.

func (*Map) Or

func (m *Map) Or(predicate func(map[interface{}]interface{}) bool) bool

Or calls predicate for every split of m sequentially. If any predicate invocation returns true, Or immediately terminates and also returns true. Otherwise, Or returns false.

While predicate is executed on a split of m, Or holds the corresponding lock.

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

func (*Map) ParallelAnd

func (m *Map) ParallelAnd(predicate func(map[interface{}]interface{}) bool) bool

ParallelAnd calls predicate for every split of m in parallel. The results of the predicate invocations are then combined with the && operator.

ParallelAnd returns only when all goroutines it spawns have terminated.

While predicate is executed on a split of m, ParallelAnd holds the corresponding lock.

If one or more predicate invocations panic, the corresponding goroutines recover the panics, and ParallelAnd eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelOr

func (m *Map) ParallelOr(predicate func(map[interface{}]interface{}) bool) bool

ParallelOr calls predicate for every split of m in parallel. The results of the predicate invocations are then combined with the || operator.

ParallelOr returns only when all goroutines it spawns have terminated.

While predicate is executed on a split of m, ParallelOr holds the corresponding lock.

If one or more predicate invocations panic, the corresponding goroutines recover the panics, and ParallelAnd eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelRange

func (m *Map) ParallelRange(f func(key, value interface{}))

ParallelRange calls f in parallel for each key and value present in the map.

While iterating through a split of m, ParallelRange holds the corresponding lock.

ParallelRange 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, ParallelRange may reflect any mapping for that key from any point during the Range call.

func (*Map) ParallelReduce

func (m *Map) ParallelReduce(
	reduce func(map[interface{}]interface{}) interface{},
	join func(x, y interface{}) interface{},
) interface{}

ParallelReduce calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

ParallelReduce returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduce holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduce eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceFloat64

func (m *Map) ParallelReduceFloat64(
	reduce func(map[interface{}]interface{}) float64,
	join func(x, y float64) float64,
) float64

ParallelReduceFloat64 calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

ParallelReduceFloat64 returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceFloat64 holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceFloat64 eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceFloat64Product

func (m *Map) ParallelReduceFloat64Product(reduce func(map[interface{}]interface{}) float64) float64

ParallelReduceFloat64Product calls reduce for every split of m in parallel. The results of the reduce invocations are then multiplied with each other.

ParallelReduceFloat64Product returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceFloat64Product holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceFloat64Product eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceFloat64Sum

func (m *Map) ParallelReduceFloat64Sum(reduce func(map[interface{}]interface{}) float64) float64

ParallelReduceFloat64Sum calls reduce for every split of m in parallel. The results of the reduce invocations are then added together.

ParallelReduceFloat64Sum returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceFloat64Sum holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceFloat64Sum eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceInt

func (m *Map) ParallelReduceInt(
	reduce func(map[interface{}]interface{}) int,
	join func(x, y int) int,
) int

ParallelReduceInt calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

While reduce is executed on a split of m, ParallelReduceInt holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceInt eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceIntProduct

func (m *Map) ParallelReduceIntProduct(reduce func(map[interface{}]interface{}) int) int

ParallelReduceIntProduct calls reduce for every split of m in parallel. The results of the reduce invocations are then multiplied with each other.

ParallelReduceIntProduct returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceIntProduct holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceIntProduct eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceIntSum

func (m *Map) ParallelReduceIntSum(reduce func(map[interface{}]interface{}) int) int

ParallelReduceIntSum calls reduce for every split of m in parallel. The results of the reduce invocations are then added together.

ParallelReduceIntSum returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceIntSum holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceIntSum eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceString

func (m *Map) ParallelReduceString(
	reduce func(map[interface{}]interface{}) string,
	join func(x, y string) string,
) string

ParallelReduceString calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

ParallelReduceString returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceString holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceString eventually panics with the left-most recovered panic value.

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

func (*Map) ParallelReduceStringSum

func (m *Map) ParallelReduceStringSum(reduce func(map[interface{}]interface{}) string) string

ParallelReduceStringSum calls reduce for every split of m in parallel. The results of the reduce invocations are then concatenated together.

ParallelReduceStringSum returns only when all goroutines it spawns have terminated.

While reduce is executed on a split of m, ParallelReduceStringSum holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and ParallelReduceStringSum eventually panics with the left-most recovered panic value.

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

func (*Map) Range

func (m *Map) Range(f func(key, value interface{}) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, Range stops the iteration.

While iterating through a split of m, Range holds the corresponding lock.

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.

func (*Map) Reduce

func (m *Map) Reduce(
	reduce func(map[interface{}]interface{}) interface{},
	join func(x, y interface{}) interface{},
) interface{}

Reduce calls reduce for every split of m sequentially. The results of the reduce invocations are then combined by repeated invocations of the join function.

While reduce is executed on a split of m, Reduce holds the corresponding lock.

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

func (*Map) ReduceFloat64

func (m *Map) ReduceFloat64(
	reduce func(map[interface{}]interface{}) float64,
	join func(x, y float64) float64,
) float64

ReduceFloat64 calls reduce for every split of m sequentially. The results of the reduce invocations are then combined by repeated invocations of the join function.

While reduce is executed on a split of m, ReduceFloat64 holds the corresponding lock.

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

func (*Map) ReduceFloat64Product

func (m *Map) ReduceFloat64Product(reduce func(map[interface{}]interface{}) float64) float64

ReduceFloat64Product calls reduce for every split of m sequentially. The results of the reduce invocations are then multiplied with each other.

While reduce is executed on a split of m, ReduceFloat64Product holds the corresponding lock.

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

func (*Map) ReduceFloat64Sum

func (m *Map) ReduceFloat64Sum(reduce func(map[interface{}]interface{}) float64) float64

ReduceFloat64Sum calls reduce for every split of m sequentially. The results of the reduce invocations are then added together.

While reduce is executed on a split of m, ReduceFloat64Sum holds the corresponding lock.

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

func (*Map) ReduceInt

func (m *Map) ReduceInt(
	reduce func(map[interface{}]interface{}) int,
	join func(x, y int) int,
) int

ReduceInt calls reduce for every split of m sequentially. The results of the reduce invocations are then combined by repeated invocations of the join function.

While reduce is executed on a split of m, ReduceInt holds the corresponding lock.

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

func (*Map) ReduceIntProduct

func (m *Map) ReduceIntProduct(reduce func(map[interface{}]interface{}) int) int

ReduceIntProduct calls reduce for every split of m sequentially. The results of the reduce invocations are then multiplied with each other.

While reduce is executed on a split of m, ReduceIntProduct holds the corresponding lock.

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

func (*Map) ReduceIntSum

func (m *Map) ReduceIntSum(reduce func(map[interface{}]interface{}) int) int

ReduceIntSum calls reduce for every split of m sequentially. The results of the reduce invocations are then added together.

While reduce is executed on a split of m, ReduceIntSum holds the corresponding lock.

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

func (*Map) ReduceString

func (m *Map) ReduceString(
	reduce func(map[interface{}]interface{}) string,
	join func(x, y string) string,
) string

ReduceString calls reduce for every split of m sequentially. The results of the reduce invocations are then combined by repeated invocations of the join function.

While reduce is executed on a split of m, ReduceString holds the corresponding lock.

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

func (*Map) ReduceStringSum

func (m *Map) ReduceStringSum(reduce func(map[interface{}]interface{}) string) string

ReduceStringSum calls reduce for every split of m sequentially. The results of the reduce invocations are then concatenated with each other.

While reduce is executed on a split of m, ReduceStringSum holds the corresponding lock.

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

func (*Map) SpeculativeAnd

func (m *Map) SpeculativeAnd(predicate func(map[interface{}]interface{}) bool) bool

SpeculativeAnd calls predicate for every split of m in parallel. SpeculativeAnd returns true if all predicate invocations return true; or SpeculativeAnd return false when at least one of them returns false, without waiting for the other predicates to terminate.

While predicate is executed on a split of m, SpeculativeAnd holds the corresponding lock.

If one or more predicate invocations panic, the corresponding goroutines recover the panics, and SpeculativeAnd eventually panics with the left-most recovered panic value.

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

func (*Map) SpeculativeOr

func (m *Map) SpeculativeOr(predicate func(map[interface{}]interface{}) bool) bool

SpeculativeOr calls predicate for every split of m in parallel. SpeculativeOr returns false if all predicate invocations return false; or SpeculativeOr return true when at least one of them returns true, without waiting for the other predicates to terminate.

While predicate is executed on a split of m, SpeculativeOr holds the corresponding lock.

If one or more predicate invocations panic, the corresponding goroutines recover the panics, and SpeculativeOr eventually panics with the left-most recovered panic value.

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

func (*Map) SpeculativeRange

func (m *Map) SpeculativeRange(f func(key, value interface{}) bool)

SpeculativeRange calls f in parallel for each key and value present in the map. If f returns false, SpeculativeRange stops the iteration, and returns without waiting for the other goroutines that it invoked to terminate.

While iterating through a split of m, SpeculativeRange holds the corresponding lock.

SpeculativeRange is useful as an alternative to ParallelRange in cases where ParallelRange tends to use computational resources for too long when false is a common and/or early return value for f. On the other hand, SpeculativeRange adds overhead, so for cases where false is an uncommon and/or late return value for f, it may be more efficient to use ParallelRange.

SpeculativeRange 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, SpeculativeRange may reflect any mapping for that key from any point during the Range call.

func (*Map) SpeculativeReduce

func (m *Map) SpeculativeReduce(
	reduce func(map[interface{}]interface{}) (interface{}, bool),
	join func(x, y interface{}) (interface{}, bool),
) (interface{}, bool)

SpeculativeReduce calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

SpeculativeReduce returns either when all goroutines it spawns have terminated with a second return value of false; or when one or more reduce or join functions return a second return value of true. In the latter case, the first return value of the left-most function that returned true as a second return value becomes the final result, without waiting for the other functions to terminate.

While reduce is executed on a split of m, SpeculativeReduce holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and SpeculativeReduce eventually panics with the left-most recovered panic value.

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

func (*Map) SpeculativeReduceFloat64

func (m *Map) SpeculativeReduceFloat64(
	reduce func(map[interface{}]interface{}) (float64, bool),
	join func(x, y float64) (float64, bool),
) (float64, bool)

SpeculativeReduceFloat64 calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

SpeculativeReduceFloat64 returns either when all goroutines it spawns have terminated with a second return value of false; or when one or more reduce or join functions return a second return value of true. In the latter case, the first return value of the left-most function that returned true as a second return value becomes the final result, without waiting for the other functions to terminate.

While reduce is executed on a split of m, SpeculativeReduceFloat64 holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and SpeculativeReduceFloat64 eventually panics with the left-most recovered panic value.

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

func (*Map) SpeculativeReduceInt

func (m *Map) SpeculativeReduceInt(
	reduce func(map[interface{}]interface{}) (int, bool),
	join func(x, y int) (int, bool),
) (int, bool)

SpeculativeReduceInt calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

SpeculativeReduceInt returns either when all goroutines it spawns have terminated with a second return value of false; or when one or more reduce or join functions return a second return value of true. In the latter case, the first return value of the left-most function that returned true as a second return value becomes the final result, without waiting for the other functions to terminate.

While reduce is executed on a split of m, SpeculativeReduceInt holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and SpeculativeReduceInt eventually panics with the left-most recovered panic value.

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

func (*Map) SpeculativeReduceString

func (m *Map) SpeculativeReduceString(
	reduce func(map[interface{}]interface{}) (string, bool),
	join func(x, y string) (string, bool),
) (string, bool)

SpeculativeReduceString calls reduce for every split of m in parallel. The results of the reduce invocations are then combined by repeated invocations of the join function.

SpeculativeReduceString returns either when all goroutines it spawns have terminated with a second return value of false; or when one or more reduce or join functions return a second return value of true. In the latter case, the first return value of the left-most function that returned true as a second return value becomes the final result, without waiting for the other functions to terminate.

While reduce is executed on a split of m, SpeculativeReduceString holds the corresponding lock.

If one or more reduce invocations panic, the corresponding goroutines recover the panics, and SpeculativeReduceString eventually panics with the left-most recovered panic value.

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

func (*Map) Split

func (m *Map) Split(key Hasher) *Split

Split retrieves the split for a particular key.

The split must be locked/unlocked properly by user programs to safely access its contents. In many cases, it is easier to use one of the high-level methods, like Load, LoadOrStore, LoadOrCompute, Delete, DeleteOrStore, DeleteOrCompute, and Modify, which implicitly take care of proper locking.

type Split

type Split struct {
	sync.RWMutex
	Map map[interface{}]interface{}
}

A Split is a partial map that belongs to a larger Map, which can be individually locked. Its enclosed map can then be individually accessed without blocking accesses to other splits.

Jump to

Keyboard shortcuts

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