linearhash

package
v0.0.0-...-dc7bb07 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

An LHash is a map structure using the linear-hashing algorithm. This implementation uses the SipHash hashing algorithm, which is available on many platforms and languages, and uses msgpack as the serialization format for the LHash state, which again, is widely available.

Multiple connections may interact with the same underlying LHash objects at the same time, as GoshawkDB ensures through the use of strong serialization that any dependent operations are safely ordered.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LHash

type LHash struct {
	// The connection used to create this LHash object. As usual with
	// GoshawkDB, objects are scoped to connections so you should not
	// use the same LHash object from multiple connections. You can
	// have multiple LHash objects for the same underlying set of
	// GoshawkDB objects.
	Conn *client.Connection
	// The underlying Object in GoshawkDB which holds the root data for
	// the LHash.
	ObjRef client.ObjectRef
	// contains filtered or unexported fields
}

func LHashFromObj

func LHashFromObj(conn *client.Connection, objRef client.ObjectRef) *LHash

Create an LHash object from an existing given GoshawkDB Object. Use this to regain access to an existing LHash which has already been created. This function does not do any initialisation: it assumes the Object passed is already initialised for LHash.

func NewEmptyLHash

func NewEmptyLHash(conn *client.Connection) (*LHash, error)

Create a brand new empty LHash. This creates a new GoshawkDB Object and initialises it for use as an LHash.

func (*LHash) Find

func (lh *LHash) Find(key []byte) (*client.ObjectRef, error)

Search the LHash for the given key. The key is hashed using the SipHash algorithm, and comparison between keys is done with bytes.Equal. If no matching key is found, a nil ObjectRef is returned.

func (*LHash) ForEach

func (lh *LHash) ForEach(f func([]byte, client.ObjectRef) error) error

Iterate over the entries in the LHash. Iteration order is undefined. Also note that as usual, the transaction in which the iteration is occurring may need to restart one or more times in which case the callback may be invoked several times for the same entry. To detect this, call ForEach from within a transaction of your own. Iteration will stop as soon as the callback returns a non-nil error, which will also abort the transaction.

func (*LHash) Put

func (lh *LHash) Put(key []byte, value client.ObjectRef) error

Idempotently add the given key and value to the LHash. The key is hashed using the SipHash algorithm, and comparison between keys is done with bytes.Equal. If a matching key is found, the corresponding value is updated.

func (*LHash) Remove

func (lh *LHash) Remove(key []byte) error

Idempotently remove any matching entry from the LHash. The key is hashed using the SipHash algorithm, and comparison between keys is done with bytes.Equal.

func (*LHash) Size

func (lh *LHash) Size() (int64, error)

Returns the number of entries in the LHash.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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