Documentation ¶
Overview ¶
package cuckoo provides a Memcache-like interface to a concurrent, in-memory Cuckoo hash map.
Index ¶
- Constants
- type CasVal
- type Cuckoo
- func (c *Cuckoo) Add(key []byte, bytes []byte, flags uint32, expires time.Time) MemopRes
- func (c *Cuckoo) Append(key []byte, bytes []byte, casid uint64) MemopRes
- func (c *Cuckoo) CAS(key []byte, bytes []byte, flags uint32, expires time.Time, casid uint64) MemopRes
- func (c *Cuckoo) Capacity() uint64
- func (c *Cuckoo) Close()
- func (c *Cuckoo) Decr(key []byte, by uint64, def uint64, expires time.Time) MemopRes
- func (c *Cuckoo) Delete(key []byte, casid uint64) MemopRes
- func (c *Cuckoo) EnableEviction()
- func (c Cuckoo) Get(key []byte) (*Memval, bool)
- func (c *Cuckoo) Incr(key []byte, by uint64, def uint64, expires time.Time) MemopRes
- func (c Cuckoo) Iterate() <-chan *Memval
- func (c Cuckoo) IterateKeys() <-chan string
- func (c *Cuckoo) Prepend(key []byte, bytes []byte, casid uint64) MemopRes
- func (c *Cuckoo) Replace(key []byte, bytes []byte, flags uint32, expires time.Time) MemopRes
- func (c *Cuckoo) Set(key []byte, bytes []byte, flags uint32, expires time.Time) MemopRes
- func (c *Cuckoo) Touch(key []byte, expires time.Time) MemopRes
- func (c *Cuckoo) TouchAll(expires time.Time)
- type Memop
- type MemopRes
- type MemopResType
- type Memval
- type SpinLock
Constants ¶
const ( STORED MemopResType = iota NOT_STORED = iota EXISTS = iota NOT_FOUND = iota CLIENT_ERROR = iota SERVER_ERROR = -1 )
const ASSOCIATIVITY int = 1 << ASSOCIATIVITY_E
ASSOCIATIVITY is the set-associativity of each Cuckoo bin
const ASSOCIATIVITY_E uint = 3
const EVICTION_THRESHOLD = 1
EVICTION_THRESHOLD sets a threshold for how many items must be evicted in the space of one second for a table resize to be performed.
const MAX_HASHES = 10
MAX_HASHES indicates the maximum number of Cuckoo hashes permitted. A higher number will increase the capacity of the map, but will slow down operations.
const MAX_SEARCH_DEPTH int = 1000
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cuckoo ¶
type Cuckoo struct {
// contains filtered or unexported fields
}
Cuckoo is an externally visible wrapper to a Cuckoo map implementation
func New ¶
New produces a new Cuckoo map. esize will be rounded to the next power of two. By default, 2 hashes are used. If esize is 0, the map will be initialized to hold 8192 elements. The map will automatically increase the number of hashes as the map fills to avoid spilling items.
func (*Cuckoo) CAS ¶
func (c *Cuckoo) CAS(key []byte, bytes []byte, flags uint32, expires time.Time, casid uint64) MemopRes
CAS overwrites the value for a key if it has not changed
func (*Cuckoo) EnableEviction ¶
func (c *Cuckoo) EnableEviction()
func (Cuckoo) IterateKeys ¶
Iterate returns a list of keys present in the map
type Memop ¶
Memop is a map operation to be performed for some key. The operation will be passed the current value (Memop{} if no value exists), and a boolean flag indicating if the key already existed in the database. The operation is executed within a lock for the given item.
type MemopRes ¶
type MemopRes struct { T MemopResType M *Memval E error }
MemopRes is a container for the result of a map operation.
type MemopResType ¶
type MemopResType int
MemopResType is a status code for the result of a map operation.
func (MemopResType) String ¶
func (t MemopResType) String() string
type Memval ¶
Memval is a container for all data a Memcache client may wish to store for a particular key.
type SpinLock ¶
type SpinLock struct {
// contains filtered or unexported fields
}
SpinLock implements a simple atomic spin lock, the zero value for a SpinLock is an unlocked spinlock.
func (*SpinLock) Lock ¶
func (sl *SpinLock) Lock()
Lock locks sl. If the lock is already in use, the caller blocks until Unlock is called
func (*SpinLock) TryLock ¶
TryLock will try to lock sl and return whether it succeed or not without blocking.
func (*SpinLock) Unlock ¶
func (sl *SpinLock) Unlock()
Unlock unlocks sl, unlike [Mutex.Unlock](http://golang.org/pkg/sync/#Mutex.Unlock), there's no harm calling it on an unlocked SpinLock