collection

package
v1.2.13-prerelease12 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 7 Imported by: 6

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 calculation and return err

type ChannelPriorityQueue added in v0.9.0

type ChannelPriorityQueue interface {
	Add(priority int, item interface{}) bool
	Remove() (interface{}, bool)
	Close()
}

ChannelPriorityQueue is an interface for a priority queue

func NewChannelPriorityQueue added in v0.9.0

func NewChannelPriorityQueue(queueSize int) ChannelPriorityQueue

NewChannelPriorityQueue returns a ChannelPriorityQueue

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
	// Len returns the number of items in the map
	Len() int
}

ConcurrentTxMap is a generic interface for any implementation of a dictionary or a key value lookup table that is thread safe, and providing functionality to modify key / value pair inside within a transaction

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 Iterator added in v0.5.8

type Iterator interface {
	// HasNext return whether this iterator has next value
	HasNext() bool
	// Next returns the next item and error
	Next() (interface{}, error)
}

Iterator represents the interface for iterator

func NewPagingIterator added in v0.5.8

func NewPagingIterator(paginationFn PaginationFn) Iterator

NewPagingIterator create a new paging iterator TODO: this implementation should be removed in favor of pagination/iterator.go

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 OrderedMap added in v0.24.0

type OrderedMap 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{})
	// Remove deletes the key from the map
	Remove(key interface{})
	// Iter returns an iterator to the map which iterates over map entries
	// in insertion order
	Iter() MapIterator
	// Len returns the number of items in the map
	Len() int
}

OrderedMap is an interface for a dictionary which during iteration return all values in their insertion order

func NewConcurrentOrderedMap added in v0.24.0

func NewConcurrentOrderedMap() OrderedMap

NewConcurrentOrderedMap creates a new thread safe OrderedMap

func NewOrderedMap added in v0.24.0

func NewOrderedMap() OrderedMap

NewOrderedMap creates a new OrderedMap implementation has O(1) complexity for all methods

type PaginationFn added in v0.5.8

type PaginationFn func(paginationToken []byte) ([]interface{}, []byte, error)

PaginationFn is the function which get a page of results

type PagingIteratorImpl added in v0.5.8

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

PagingIteratorImpl is the implementation of PagingIterator

func (*PagingIteratorImpl) HasNext added in v0.5.8

func (iter *PagingIteratorImpl) HasNext() bool

HasNext return whether has next item or err

func (*PagingIteratorImpl) Next added in v0.5.8

func (iter *PagingIteratorImpl) Next() (interface{}, error)

Next return next item or err

type PredicateFunc

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

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

type Queue added in v0.5.8

type Queue interface {
	// Peek returns the first item of the queue
	Peek() interface{}
	// Add push an item to the queue
	Add(item interface{})
	// Remove pop an item from the queue
	Remove() interface{}
	// IsEmpty indicate if the queue is empty
	IsEmpty() bool
	// Len return the size of the queue
	Len() int
}

Queue is the interface for queue

func NewConcurrentPriorityQueue added in v0.5.8

func NewConcurrentPriorityQueue(compareLess func(this interface{}, other interface{}) bool) Queue

NewConcurrentPriorityQueue create a new concurrent priority queue

func NewConcurrentQueue added in v0.13.0

func NewConcurrentQueue() Queue

NewConcurrentQueue creates a new concurrent queue

func NewPriorityQueue added in v0.5.8

func NewPriorityQueue(compareLess func(this interface{}, other interface{}) bool) Queue

NewPriorityQueue create a new priority queue

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) Len added in v0.5.8

func (cmap *ShardedConcurrentTxMap) Len() int

Len returns the number of items in the map

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

Jump to

Keyboard shortcuts

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