xsync

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

xsync

Install

go get -u github.com/chenquan/go-pkg/xsync

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map from standard library

func (*Map) Clear added in v0.1.12

func (m *Map) Clear()

Clear clears all elements.

func (*Map) ComputeIfAbsent

func (m *Map) ComputeIfAbsent(key interface{}, computeFunc func(key interface{}) interface{}) (actual interface{}, loaded bool)

ComputeIfAbsent if the value corresponding to the key does not exist, use the recalculated value obtained by remappingFunction and save it as the value of the key, otherwise return the value.

func (*Map) ComputeIfPresent

func (m *Map) ComputeIfPresent(key interface{}, computeFunc func(key, value interface{}) interface{}) (actual interface{}, exist bool)

ComputeIfPresent if the value corresponding to the key does not exist, the null is returned, and if it exists, the value recalculated by remappingFunction is returned.

func (*Map) Delete

func (m *Map) Delete(key interface{})

Delete deletes the value for a key.

func (*Map) Load

func (m *Map) Load(key interface{}) (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) LoadAndDelete

func (m *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*Map) LoadOrStore

func (m *Map) LoadOrStore(key, 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) 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.

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.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*Map) Store

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

Store sets the value for a key.

type ResourceManager

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

ResourceManager is a resource manager.

func NewResourceManager

func NewResourceManager() *ResourceManager

NewResourceManager returns a ResourceManager.

func (*ResourceManager) Close

func (m *ResourceManager) Close() error

Close the manager. Don't use the ResourceManager after Close() called.

func (*ResourceManager) Get

func (m *ResourceManager) Get(key string, create func() (io.Closer, error)) (io.Closer, error)

Get returns the resource associated with given key.

func (*ResourceManager) Remove

func (m *ResourceManager) Remove(key string) (exist bool)

Remove the resource associated with given key and return it if existed.

type SharedBlockMap added in v0.1.12

type SharedBlockMap = Map

SharedBlockMap is an alias that describes the block map.

type SharedMap added in v0.1.12

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

SharedMap represents a segment lock map.

func NewSharedMap added in v0.1.15

func NewSharedMap(opts ...SharedMapOption) *SharedMap

NewSharedMap returns a SharedMap.

func (SharedMap) Clear added in v0.1.12

func (m SharedMap) Clear()

Clear removes all items from map.

func (*SharedMap) ComputeIfAbsent added in v0.1.12

func (m *SharedMap) ComputeIfAbsent(key string, computeFunc func(key string) interface{}) (actual interface{}, loaded bool)

ComputeIfAbsent if the value corresponding to the key does not exist, use the recalculated value obtained by remappingFunction and save it as the value of the key, otherwise return the value.

func (*SharedMap) ComputeIfPresent added in v0.1.12

func (m *SharedMap) ComputeIfPresent(key string, computeFunc func(key string, value interface{}) interface{}) (actual interface{}, exist bool)

ComputeIfPresent if the value corresponding to the key does not exist, the null is returned, and if it exists, the value recalculated by remappingFunction is returned.

func (SharedMap) Delete added in v0.1.12

func (m SharedMap) Delete(key string)

Delete deletes an element from the map.

func (SharedMap) GetShard added in v0.1.12

func (m SharedMap) GetShard(key string) *SharedBlockMap

GetShard returns shard under given key.

func (*SharedMap) Has added in v0.1.12

func (m *SharedMap) Has(key string) bool

Has looks up an item under specified key.

func (*SharedMap) Load added in v0.1.12

func (m *SharedMap) Load(key string) (interface{}, 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 (*SharedMap) LoadOrStore added in v0.1.12

func (m *SharedMap) LoadOrStore(key string, value interface{}) bool

LoadOrStore the given value under the specified key if no value was associated with it.

func (SharedMap) MStore added in v0.1.12

func (m SharedMap) MStore(data map[string]interface{})

MStore sets multiple keys and values.

func (*SharedMap) Range added in v0.1.12

func (m *SharedMap) Range(fn 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.

func (SharedMap) Store added in v0.1.12

func (m SharedMap) Store(key string, value interface{})

Store sets the value for a key.

type SharedMapOption added in v0.1.12

type SharedMapOption func(*sharedMapOptions)

SharedMapOption configuration function of SharedMap.

func WithShardBlockSize added in v0.1.12

func WithShardBlockSize(shardBlockSize int) SharedMapOption

WithShardBlockSize returns a configuration that sets the size of the number of segments.

type Spinlock

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

Spinlock represents a spin lock.

func (*Spinlock) Lock

func (lock *Spinlock) Lock()

Lock locks the Spinlock.

func (*Spinlock) TryLock

func (lock *Spinlock) TryLock() bool

TryLock tries to lock the Spinlock.

func (*Spinlock) Unlock

func (lock *Spinlock) Unlock()

Unlock unlocks the Spinlock.

Jump to

Keyboard shortcuts

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