cuckoo

package
v0.0.0-...-030ecf0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

package cuckoo provides a Memcache-like interface to a concurrent, in-memory Cuckoo hash map.

Index

Constants

View Source
const (
	STORED       MemopResType = iota
	NOT_STORED                = iota
	EXISTS                    = iota
	NOT_FOUND                 = iota
	CLIENT_ERROR              = iota
	SERVER_ERROR              = -1
)
View Source
const ASSOCIATIVITY int = 1 << ASSOCIATIVITY_E

ASSOCIATIVITY is the set-associativity of each Cuckoo bin

View Source
const ASSOCIATIVITY_E uint = 3
View Source
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.

View Source
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.

View Source
const MAX_SEARCH_DEPTH int = 1000

Variables

This section is empty.

Functions

This section is empty.

Types

type CasVal

type CasVal struct {
	Casid  uint64
	NewVal uint64
}

CasPMVal is used to hold both CAS and value for incr/decr operations

type Cuckoo

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

Cuckoo is an externally visible wrapper to a Cuckoo map implementation

func New

func New(esize uint64) (c *Cuckoo)

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) Add

func (c *Cuckoo) Add(key []byte, bytes []byte, flags uint32, expires time.Time) MemopRes

Add adds a non-existing key

func (*Cuckoo) Append

func (c *Cuckoo) Append(key []byte, bytes []byte, casid uint64) MemopRes

Append adds to an existing key

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) Capacity

func (c *Cuckoo) Capacity() uint64

func (*Cuckoo) Close

func (c *Cuckoo) Close()

func (*Cuckoo) Decr

func (c *Cuckoo) Decr(key []byte, by uint64, def uint64, expires time.Time) MemopRes

Decr decrements the value for an existing key

func (*Cuckoo) Delete

func (c *Cuckoo) Delete(key []byte, casid uint64) MemopRes

Delete removes the value for the given key

func (*Cuckoo) EnableEviction

func (c *Cuckoo) EnableEviction()

func (Cuckoo) Get

func (c Cuckoo) Get(key []byte) (*Memval, bool)

Get returns the current value for the given key

func (*Cuckoo) Incr

func (c *Cuckoo) Incr(key []byte, by uint64, def uint64, expires time.Time) MemopRes

Incr increments the value for an existing key

func (Cuckoo) Iterate

func (c Cuckoo) Iterate() <-chan *Memval

Iterate returns a list of Memvals present in the map

func (Cuckoo) IterateKeys

func (c Cuckoo) IterateKeys() <-chan string

Iterate returns a list of keys present in the map

func (*Cuckoo) Prepend

func (c *Cuckoo) Prepend(key []byte, bytes []byte, casid uint64) MemopRes

Prepend adds to the beginning of an existing key

func (*Cuckoo) Replace

func (c *Cuckoo) Replace(key []byte, bytes []byte, flags uint32, expires time.Time) MemopRes

Replace replaces an existing key

func (*Cuckoo) Set

func (c *Cuckoo) Set(key []byte, bytes []byte, flags uint32, expires time.Time) MemopRes

Set overwites the given key

func (*Cuckoo) Touch

func (c *Cuckoo) Touch(key []byte, expires time.Time) MemopRes

Touch updates the expiration time for an existing key

func (*Cuckoo) TouchAll

func (c *Cuckoo) TouchAll(expires time.Time)

TouchAll updates the expiration time for all entries

type Memop

type Memop func(Memval, bool) (Memval, MemopRes)

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

type Memval struct {
	Bytes   []byte
	Flags   uint32
	Casid   uint64
	Expires time.Time
}

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) String

func (sl *SpinLock) String() string

func (*SpinLock) TryLock

func (sl *SpinLock) TryLock() bool

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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