Documentation ¶
Overview ¶
Package storage provides a thread safe hash table implementation. The hash table is implemented internally as a tree structure and is self-pruning. The hash table uses a 32-bit FNV hash and each node of the tree represents 1 byte in the hash. The intention is to allow movement of entire nodes of the tree between storage instances.
Index ¶
- func Hash(key string) uint32
- type GetNodeRequest
- type GetRequest
- type Hashtable
- func (db *Hashtable) FindNode(id NodeLocator) (*Node, []*Node)
- func (db *Hashtable) FindNodeRecurse(id []byte, parent *Node, path []*Node) (*Node, []*Node)
- func (db *Hashtable) Get(key string) string
- func (db *Hashtable) Remove(key string)
- func (db *Hashtable) RemoveNode(id NodeLocator)
- func (db *Hashtable) Set(key string, value string)
- func (db *Hashtable) SetNode(id NodeLocator, value *Node) *Node
- func (db *Hashtable) SetNodeValue(id NodeLocator, key string, value string) *Node
- type Instance
- type Node
- type NodeKeyValuePair
- type NodeLocator
- type NodeResult
- type Result
- type SetNodeRequest
- type SetRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GetNodeRequest ¶
type GetNodeRequest struct { ID NodeLocator Remove bool Result chan NodeResult }
GetNodeRequest is used to request an entire node of the storage tree.
type GetRequest ¶
GetRequest is used to retrieve a value and optionally remove it from the storage tree.
type Hashtable ¶
type Hashtable struct {
// contains filtered or unexported fields
}
Hashtable implements a tree based hashtable
func (*Hashtable) FindNode ¶
func (db *Hashtable) FindNode(id NodeLocator) (*Node, []*Node)
FindNode returns a node and the path to its parent node
func (*Hashtable) FindNodeRecurse ¶
FindNodeRecurse returns a node and the path to its parent node
func (*Hashtable) RemoveNode ¶
func (db *Hashtable) RemoveNode(id NodeLocator)
RemoveNode removes a given node from the tree
func (*Hashtable) SetNode ¶
func (db *Hashtable) SetNode(id NodeLocator, value *Node) *Node
SetNode sets a given node in the tree
func (*Hashtable) SetNodeValue ¶
func (db *Hashtable) SetNodeValue(id NodeLocator, key string, value string) *Node
SetNodeValue sets a key/value pair on a given node
type Instance ¶
type Instance struct { // GetNode retrieves a node from the storage tree, optionally removing it GetNode chan GetNodeRequest // SetNode sets a node in the storage tree SetNode chan SetNodeRequest // Shutdown stops the storage worker thread Shutdown chan bool // Logger is the logger instance used by the storage instance Logger *log.Logger // Path is the path to the data file maintained by this storage instance Path string // contains filtered or unexported fields }
Instance represents a storage tree instance
func New ¶
New creates a new Storage instance. It also loads the data file if it exists and starts the storage thread.
type Node ¶
type Node struct { Children [256]*Node // contains filtered or unexported fields }
Node represents a single node in the storage tree
func (*Node) IsEmpty ¶
IsEmpty returns true if this node is empty. Leaf nodes are empty if they have no value. Non-leaf nodes are empty if they have no children.
func (*Node) RemoveValue ¶
RemoveValue removes the given value from the node
type NodeKeyValuePair ¶
NodeKeyValuePair holds a key/value pair
type NodeLocator ¶
NodeLocator provides an address to a specific node in the storage tree.
func GetNodeLocator ¶
func GetNodeLocator(id string) NodeLocator
GetNodeLocator returns a NodeLocator for this ID
func (NodeLocator) GetBytes ¶
func (id NodeLocator) GetBytes() []byte
GetBytes returns a byte slice representing this node locator
type NodeResult ¶
type NodeResult struct { ID NodeLocator Value *Node }
NodeResult is returned from GetNode and SetNode
type SetNodeRequest ¶
type SetNodeRequest struct { ID NodeLocator Value *Node Result chan NodeResult }
SetNodeRequest is used to set an entire node of the storage tree.
type SetRequest ¶
SetRequest is used to set a value in the storage tree.