ztcputil

package
v0.0.0-...-a0ddb2b Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const BILL = 1_000_000_000
View Source
const BuffSize = 1000
View Source
const CRound = 10
View Source
const ChanSize = 1000 * 100
View Source
const ENDLINE = "#\t#" //
View Source
const ENDLINE_LENGTH = len(ENDLINE)
View Source
const FRAMESPLIT = "|"
View Source
const NCpu = 12
View Source
const NRun = 10_000_000
View Source
const SendSize = 999
View Source
const TimeToFlush = time.Millisecond

Variables

View Source
var ENDBYTE = []byte(ENDLINE)
View Source
var SHARD_COUNT = 32

Functions

func Commaize

func Commaize(n int64) string

func Now

func Now() int64

func ReadWithEnd

func ReadWithEnd(reader *bufio.Reader) ([]byte, error)

func ThreadHash

func ThreadHash() uint

Types

type ConcurrentMap

type ConcurrentMap []*ConcurrentMapShared

A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (SHARD_COUNT) map shards.

func CMapCreate

func CMapCreate() ConcurrentMap

Creates a new concurrent map.

func (ConcurrentMap) Clear

func (m ConcurrentMap) Clear()

Clear removes all items from map.

func (ConcurrentMap) Count

func (m ConcurrentMap) Count() int

Count returns the number of elements within the map.

func (ConcurrentMap) Get

func (m ConcurrentMap) Get(key string) (interface{}, bool)

Get retrieves an element from map under given key.

func (ConcurrentMap) GetShard

func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared

GetShard returns shard under given key

func (ConcurrentMap) Has

func (m ConcurrentMap) Has(key string) bool

Looks up an item under specified key

func (ConcurrentMap) IsEmpty

func (m ConcurrentMap) IsEmpty() bool

IsEmpty checks if map is empty.

func (ConcurrentMap) Items

func (m ConcurrentMap) Items() map[string]interface{}

Items returns all items as map[string]interface{}

func (ConcurrentMap) Iter deprecated

func (m ConcurrentMap) Iter() <-chan Tuple

Iter returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (ConcurrentMap) IterBuffered

func (m ConcurrentMap) IterBuffered() <-chan Tuple

IterBuffered returns a buffered iterator which could be used in a for range loop.

func (ConcurrentMap) IterCb

func (m ConcurrentMap) IterCb(fn IterCb)

Callback based iterator, cheapest way to read all elements in a map.

func (ConcurrentMap) Keys

func (m ConcurrentMap) Keys() []string

Keys returns all keys as []string

func (ConcurrentMap) MSet

func (m ConcurrentMap) MSet(data map[string]interface{})

func (ConcurrentMap) MarshalJSON

func (m ConcurrentMap) MarshalJSON() ([]byte, error)

Reviles ConcurrentMap "private" variables to json marshal.

func (ConcurrentMap) Pop

func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)

Pop removes an element from the map and returns it

func (ConcurrentMap) Remove

func (m ConcurrentMap) Remove(key string)

Remove removes an element from the map.

func (ConcurrentMap) RemoveCb

func (m ConcurrentMap) RemoveCb(key string, cb RemoveCb) bool

RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)

func (ConcurrentMap) Set

func (m ConcurrentMap) Set(key string, value interface{})

Sets the given value under the specified key.

func (ConcurrentMap) SetIfAbsent

func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool

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

func (ConcurrentMap) Upsert

func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})

Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared

type ConcurrentMapShared struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

A "thread" safe string to anything map.

type Count32

type Count32 int32

fast count - fast get

func Count32Create

func Count32Create() *Count32

func (*Count32) Get

func (c *Count32) Get() int32

func (*Count32) Inc

func (c *Count32) Inc() int32

func (*Count32) IncMax

func (c *Count32) IncMax(i int32) int32

func (*Count32) IncMaxInt

func (c *Count32) IncMaxInt(i int32) int

type Int64

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

Int64 is an int64 atomic counter.

func MakeInt64

func MakeInt64() Int64

MakeInt64 creates a new Int64 object. Int64 objects must be created by this function, simply initialized doesn't work.

func (*Int64) Add

func (c *Int64) Add(n int64)

Add adds n to the counter.

func (*Int64) Inc

func (c *Int64) Inc()

Inc adds 1 to the counter.

func (*Int64) Read

func (c *Int64) Read() int64

Read return the current value. it is a little slow so it should not be called frequently. Th result is not guaranteed to be accurate in race conditions.

func (*Int64) Set

func (c *Int64) Set(n int64)

Set set the value of the counter to n.

func (*Int64) Swap

func (c *Int64) Swap(n int64) int64

Swap returns the current value and swap it with n.

type IterCb

type IterCb func(key string, v interface{})

Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type PerformanceCounter

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

func PerformanceCounterCreate

func PerformanceCounterCreate(step int, timeToShow int, prefix string) *PerformanceCounter

func (*PerformanceCounter) Result

func (s *PerformanceCounter) Result()

func (*PerformanceCounter) Step

func (s *PerformanceCounter) Step(show ...bool)

Count step default is hidden

type RemoveCb

type RemoveCb func(key string, v interface{}, exists bool) bool

RemoveCb is a callback executed in a map.RemoveCb() call, while Lock is held If returns true, the element will be removed from the map

type Tuple

type Tuple struct {
	Key string
	Val interface{}
}

Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertCb

type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}

Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Jump to

Keyboard shortcuts

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