Documentation ¶
Overview ¶
Copyright 2014 loolgame Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2014 mqant Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2014 loolgame Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package queue provides a fast, ring-buffer queue based on the version suggested by Dariusz Górecki. Using this instead of other, simpler, queue implementations (slice+append or linked list) provides substantial memory and time benefits, and fewer GC pauses. The queue implemented here is as fast as it is for an additional reason: it is *not* thread-safe.
Copyright 2014 mqant Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2014 mqant Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2014 mqantserver Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2014 mqant Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func Base62ToInt(str string) int64
- func BoolToBytes(v bool) []byte
- func BytesToBool(buf []byte) bool
- func BytesToFloat32(bytes []byte) float32
- func BytesToFloat64(bytes []byte) float64
- func BytesToInt32(buf []byte) int32
- func BytesToInt64(buf []byte) int64
- func BytesToMap(bytes []byte) (map[string]interface{}, error)
- func BytesToMapString(bytes []byte) (map[string]string, error)
- func Float32ToBytes(float float32) []byte
- func Float64ToBytes(float float64) []byte
- func Int32ToBytes(i int32) []byte
- func Int64ToBytes(i int64) []byte
- func IntToBase62(number int64) string
- func MapToBytes(jmap map[string]interface{}) ([]byte, error)
- func MapToBytesString(jmap map[string]string) ([]byte, error)
- func RandInt64(min, max int64) int64
- func Struct2Map(obj interface{}) map[string]interface{}
- type BeeMap
- type ConcurrentMap
- func (m ConcurrentMap) Count() int
- func (m ConcurrentMap) Get(key string) (interface{}, bool)
- func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared
- func (m ConcurrentMap) Has(key string) bool
- func (m ConcurrentMap) IsEmpty() bool
- func (m ConcurrentMap) Items() map[string]interface{}
- func (m ConcurrentMap) Iter() <-chan Tupledeprecated
- func (m ConcurrentMap) IterBuffered() <-chan Tuple
- func (m ConcurrentMap) IterCb(fn IterCb)
- func (m ConcurrentMap) Keys() []string
- func (m ConcurrentMap) MSet(data map[string]interface{})
- func (m ConcurrentMap) MarshalJSON() ([]byte, error)
- func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)
- func (m ConcurrentMap) Remove(key string)
- func (m ConcurrentMap) RemoveCb(key string, cb RemoveCb) bool
- func (m ConcurrentMap) Set(key string, value interface{})
- func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool
- func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})
- type ConcurrentMapShared
- type ID
- type IterCb
- type Queue
- type RedisFactory
- type RemoveCb
- type SyncQueue
- type Tuple
- type UpsertCb
Constants ¶
const CODE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const CODE_LENTH = 62
Variables ¶
var EDOC = map[string]int64{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34, "z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61}
var SHARD_COUNT = 32
Functions ¶
func BoolToBytes ¶
func BytesToBool ¶
func BytesToFloat32 ¶
func BytesToFloat64 ¶
func BytesToInt32 ¶
func BytesToInt64 ¶
func BytesToMap ¶
func Float32ToBytes ¶
func Float64ToBytes ¶
func Int32ToBytes ¶
func Int64ToBytes ¶
func MapToBytes ¶
func Struct2Map ¶
func Struct2Map(obj interface{}) map[string]interface{}
Types ¶
type BeeMap ¶
type BeeMap struct {
// contains filtered or unexported fields
}
BeeMap is a map with lock
func (*BeeMap) Get ¶
func (m *BeeMap) Get(k interface{}) interface{}
Get from maps return the k's value
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 (ConcurrentMap) Count ¶
func (m ConcurrentMap) Count() int
Returns the number of elements within the map.
func (ConcurrentMap) Get ¶
func (m ConcurrentMap) Get(key string) (interface{}, bool)
Retrieves an element from map under given key.
func (ConcurrentMap) GetShard ¶
func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared
Returns shard under given key
func (ConcurrentMap) Has ¶
func (m ConcurrentMap) Has(key string) bool
Looks up an item under specified key
func (ConcurrentMap) Items ¶
func (m ConcurrentMap) Items() map[string]interface{}
Returns all items as map[string]interface{}
func (ConcurrentMap) Iter
deprecated
func (m ConcurrentMap) Iter() <-chan Tuple
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
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) 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)
Removes an element from the map and returns it
func (ConcurrentMap) Remove ¶
func (m ConcurrentMap) Remove(key string)
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 { // contains filtered or unexported fields }
A "thread" safe string to anything map.
type ID ¶
type ID uint64
An ID is a unique, uniformly distributed 64-bit ID.
func GenerateID ¶
func GenerateID() ID
generateID returns a randomly-generated 64-bit ID. This function is thread-safe. IDs are produced by consuming an AES-CTR-128 keystream in 64-bit chunks. The AES key is randomly generated on initialization, as is the counter's initial state. On machines with AES-NI support, ID generation takes ~30ns and generates no garbage.
func (ID) MarshalJSON ¶
MarshalJSON encodes the ID as a hex string.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON decodes the given data as either a hexadecimal string or JSON integer.
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 Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue represents a single instance of the queue data structure.
func (*Queue) Add ¶
func (q *Queue) Add(elem interface{})
Add puts an element on the end of the queue.
func (*Queue) Get ¶
Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.
type RedisFactory ¶
type RedisFactory struct {
// contains filtered or unexported fields
}
func GetRedisFactory ¶
func GetRedisFactory() *RedisFactory
func (RedisFactory) CloseAllPool ¶
func (this RedisFactory) CloseAllPool()
type RemoveCb ¶
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 SyncQueue ¶
type SyncQueue struct {
// contains filtered or unexported fields
}
Synchronous FIFO queue
func (*SyncQueue) Close ¶
func (q *SyncQueue) Close()
Close SyncQueue
After close, Pop will return nil without block, and TryPop will return v=nil, ok=True
func (*SyncQueue) Pop ¶
func (q *SyncQueue) Pop() (v interface{})
Pop an item from SyncQueue, will block if SyncQueue is empty
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