dict

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentDict

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

ConcurrentDict is thread safe map using sharding lock

func MakeConcurrent

func MakeConcurrent(shardCount int) *ConcurrentDict

MakeConcurrent creates ConcurrentDict with the given shard count

func (*ConcurrentDict) Clear added in v1.2.8

func (dict *ConcurrentDict) Clear()

Clear removes all keys in dict

func (*ConcurrentDict) ForEach

func (dict *ConcurrentDict) ForEach(consumer Consumer)

ForEach traversal the dict it may not visits new entry inserted during traversal

func (*ConcurrentDict) Get

func (dict *ConcurrentDict) Get(key string) (val interface{}, exists bool)

Get returns the binding value and whether the key is exist

func (*ConcurrentDict) GetWithLock added in v1.2.9

func (dict *ConcurrentDict) GetWithLock(key string) (val interface{}, exists bool)

func (*ConcurrentDict) Keys

func (dict *ConcurrentDict) Keys() []string

Keys returns all keys in dict

func (*ConcurrentDict) Len

func (dict *ConcurrentDict) Len() int

Len returns the number of dict

func (*ConcurrentDict) Put

func (dict *ConcurrentDict) Put(key string, val interface{}) (result int)

Put puts key value into dict and returns the number of new inserted key-value

func (*ConcurrentDict) PutIfAbsent

func (dict *ConcurrentDict) PutIfAbsent(key string, val interface{}) (result int)

PutIfAbsent puts value if the key is not exists and returns the number of updated key-value

func (*ConcurrentDict) PutIfAbsentWithLock added in v1.2.9

func (dict *ConcurrentDict) PutIfAbsentWithLock(key string, val interface{}) (result int)

func (*ConcurrentDict) PutIfExists

func (dict *ConcurrentDict) PutIfExists(key string, val interface{}) (result int)

PutIfExists puts value if the key is exist and returns the number of inserted key-value

func (*ConcurrentDict) PutIfExistsWithLock added in v1.2.9

func (dict *ConcurrentDict) PutIfExistsWithLock(key string, val interface{}) (result int)

func (*ConcurrentDict) PutWithLock added in v1.2.9

func (dict *ConcurrentDict) PutWithLock(key string, val interface{}) (result int)

func (*ConcurrentDict) RWLocks added in v1.2.9

func (dict *ConcurrentDict) RWLocks(writeKeys []string, readKeys []string)

RWLocks locks write keys and read keys together. allow duplicate keys

func (*ConcurrentDict) RWUnLocks added in v1.2.9

func (dict *ConcurrentDict) RWUnLocks(writeKeys []string, readKeys []string)

RWUnLocks unlocks write keys and read keys together. allow duplicate keys

func (*ConcurrentDict) RandomDistinctKeys

func (dict *ConcurrentDict) RandomDistinctKeys(limit int) []string

RandomDistinctKeys randomly returns keys of the given number, won't contain duplicated key

func (*ConcurrentDict) RandomKeys

func (dict *ConcurrentDict) RandomKeys(limit int) []string

RandomKeys randomly returns keys of the given number, may contain duplicated key

func (*ConcurrentDict) Remove

func (dict *ConcurrentDict) Remove(key string) (result int)

Remove removes the key and return the number of deleted key-value

func (*ConcurrentDict) RemoveWithLock added in v1.2.9

func (dict *ConcurrentDict) RemoveWithLock(key string) (result int)

type Consumer

type Consumer func(key string, val interface{}) bool

Consumer is used to traversal dict, if it returns false the traversal will be break

type Dict

type Dict interface {
	Get(key string) (val interface{}, exists bool)
	Len() int
	Put(key string, val interface{}) (result int)
	PutIfAbsent(key string, val interface{}) (result int)
	PutIfExists(key string, val interface{}) (result int)
	Remove(key string) (result int)
	ForEach(consumer Consumer)
	Keys() []string
	RandomKeys(limit int) []string
	RandomDistinctKeys(limit int) []string
	Clear()
}

Dict is interface of a key-value data structure

type SimpleDict

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

SimpleDict wraps a map, it is not thread safe

func MakeSimple

func MakeSimple() *SimpleDict

MakeSimple makes a new map

func (*SimpleDict) Clear added in v1.2.8

func (dict *SimpleDict) Clear()

Clear removes all keys in dict

func (*SimpleDict) ForEach

func (dict *SimpleDict) ForEach(consumer Consumer)

ForEach traversal the dict

func (*SimpleDict) Get

func (dict *SimpleDict) Get(key string) (val interface{}, exists bool)

Get returns the binding value and whether the key is exist

func (*SimpleDict) Keys

func (dict *SimpleDict) Keys() []string

Keys returns all keys in dict

func (*SimpleDict) Len

func (dict *SimpleDict) Len() int

Len returns the number of dict

func (*SimpleDict) Put

func (dict *SimpleDict) Put(key string, val interface{}) (result int)

Put puts key value into dict and returns the number of new inserted key-value

func (*SimpleDict) PutIfAbsent

func (dict *SimpleDict) PutIfAbsent(key string, val interface{}) (result int)

PutIfAbsent puts value if the key is not exists and returns the number of updated key-value

func (*SimpleDict) PutIfExists

func (dict *SimpleDict) PutIfExists(key string, val interface{}) (result int)

PutIfExists puts value if the key is exist and returns the number of inserted key-value

func (*SimpleDict) RandomDistinctKeys

func (dict *SimpleDict) RandomDistinctKeys(limit int) []string

RandomDistinctKeys randomly returns keys of the given number, won't contain duplicated key

func (*SimpleDict) RandomKeys

func (dict *SimpleDict) RandomKeys(limit int) []string

RandomKeys randomly returns keys of the given number, may contain duplicated key

func (*SimpleDict) Remove

func (dict *SimpleDict) Remove(key string) (result int)

Remove removes the key and return the number of deleted key-value

Jump to

Keyboard shortcuts

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