collection

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2019 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// UUIDStringLength is the length of an UUID represented as a hex string
	UUIDStringLength = 36 // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
)

Variables

This section is empty.

Functions

func MaxInt

func MaxInt(a, b int) int

MaxInt returns the max of given two integers

func MaxInt64

func MaxInt64(a, b int64) int64

MaxInt64 returns the max of given two integers

func MinInt

func MinInt(a, b int) int

MinInt returns the min of given two integers

func MinInt64

func MinInt64(a, b int64) int64

MinInt64 returns the min of given two integers

func UUIDHashCode

func UUIDHashCode(input interface{}) uint32

UUIDHashCode is a hash function for hashing string uuid if the uuid is malformed, then the hash function always returns 0 as the hash value

Types

type ActionFunc

type ActionFunc func(key interface{}, value interface{}) error

ActionFunc take a key and value, do calulation and return err

type ConcurrentTxMap

type ConcurrentTxMap interface {
	// Get returns the value for the given key
	Get(key interface{}) (interface{}, bool)
	// Contains returns true if the key exist and false otherwise
	Contains(key interface{}) bool
	// Put records the mapping from given key to value
	Put(key interface{}, value interface{})
	// PutIfNotExist records the key value mapping only
	// if the mapping does not already exist
	PutIfNotExist(key interface{}, value interface{}) bool
	// Remove deletes the key from the map
	Remove(key interface{})
	// GetAndDo returns the value corresponding to the key, and apply fn to key value before return value
	// return (value, value exist or not, error when evaluation fn)
	GetAndDo(key interface{}, fn ActionFunc) (interface{}, bool, error)
	// PutOrDo put the key value in the map, if key does not exists, otherwise, call fn with existing key and value
	// return (value, fn evaluated or not, error when evaluation fn)
	PutOrDo(key interface{}, value interface{}, fn ActionFunc) (interface{}, bool, error)
	// RemoveIf deletes the given key from the map if fn return true
	// return whether the key is removed or not
	RemoveIf(key interface{}, fn PredicateFunc) bool
	// Iter returns an iterator to the map
	Iter() MapIterator
	// Size returns the number of items in the map
	Size() int
}

ConcurrentTxMap is a generic interface for any implementation of a dictionary or a key value lookup table that is thread safe, and

func NewShardedConcurrentTxMap

func NewShardedConcurrentTxMap(initialCap int, hashfn HashFunc) ConcurrentTxMap

NewShardedConcurrentTxMap returns an instance of ShardedConcurrentMap

ShardedConcurrentMap is a thread safe map that maintains upto nShards number of maps internally to allow nShards writers to be acive at the same time. This map *does not* use re-entrant locks, so access to the map during iterator can cause a dead lock.

@param initialSz

The initial size for the map

@param hashfn

The hash function to use for sharding

type HashFunc

type HashFunc func(interface{}) uint32

HashFunc represents a hash function for string

type MapEntry

type MapEntry struct {
	// Key represents the key
	Key interface{}
	// Value represents the value
	Value interface{}
}

MapEntry represents a key-value entry within the map

type MapIterator

type MapIterator interface {
	// Close closes the iterator
	// and releases any allocated resources
	Close()
	// Entries returns a channel of MapEntry
	// objects that can be used in a range loop
	Entries() <-chan *MapEntry
}

MapIterator represents the interface for map iterators

type PredicateFunc

type PredicateFunc func(key interface{}, value interface{}) bool

PredicateFunc take a key and value, do calulation and return boolean

type ShardedConcurrentTxMap

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

ShardedConcurrentTxMap is an implementation of ConcurrentMap that internally uses multiple sharded maps to increase parallelism

func (*ShardedConcurrentTxMap) Contains

func (cmap *ShardedConcurrentTxMap) Contains(key interface{}) bool

Contains returns true if the key exist and false otherwise

func (*ShardedConcurrentTxMap) Get

func (cmap *ShardedConcurrentTxMap) Get(key interface{}) (interface{}, bool)

Get returns the value corresponding to the key, if it exist

func (*ShardedConcurrentTxMap) GetAndDo

func (cmap *ShardedConcurrentTxMap) GetAndDo(key interface{}, fn ActionFunc) (interface{}, bool, error)

GetAndDo returns the value corresponding to the key, and apply fn to key value before return value return (value, value exist or not, error when evaluation fn)

func (*ShardedConcurrentTxMap) Iter

func (cmap *ShardedConcurrentTxMap) Iter() MapIterator

Iter returns an iterator to the map. This map does not use re-entrant locks, so access or modification to the map during iteration can cause a dead lock.

func (*ShardedConcurrentTxMap) Put

func (cmap *ShardedConcurrentTxMap) Put(key interface{}, value interface{})

Put records the given key value mapping. Overwrites previous values

func (*ShardedConcurrentTxMap) PutIfNotExist

func (cmap *ShardedConcurrentTxMap) PutIfNotExist(key interface{}, value interface{}) bool

PutIfNotExist records the mapping, if there is no mapping for this key already Returns true if the mapping was recorded, false otherwise

func (*ShardedConcurrentTxMap) PutOrDo

func (cmap *ShardedConcurrentTxMap) PutOrDo(key interface{}, value interface{}, fn ActionFunc) (interface{}, bool, error)

PutOrDo put the key value in the map, if key does not exists, otherwise, call fn with existing key and value return (value, fn evaluated or not, error when evaluation fn)

func (*ShardedConcurrentTxMap) Remove

func (cmap *ShardedConcurrentTxMap) Remove(key interface{})

Remove deletes the given key from the map

func (*ShardedConcurrentTxMap) RemoveIf

func (cmap *ShardedConcurrentTxMap) RemoveIf(key interface{}, fn PredicateFunc) bool

RemoveIf deletes the given key from the map if fn return true

func (*ShardedConcurrentTxMap) Size

func (cmap *ShardedConcurrentTxMap) Size() int

Size returns the number of items in the map

Jump to

Keyboard shortcuts

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