pool

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2016 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

maintain severa pools of a number of elements in key->value form

This maintains a LevelDB database split into a series of tables. Each table is defined by a prefix byte.

Index

Constants

View Source
const (
	// networking pools
	Peers        = nameb('P')
	RPCs         = nameb('R')
	Certificates = nameb('C')

	// transaction data pools
	TransactionData  = nameb('T')
	TransactionState = nameb('S')

	// transaction index pools
	PendingIndex  = nameb('U')
	VerifiedIndex = nameb('V')

	// asset
	AssetData = nameb('I')

	// ownership indexes
	OwnerCount  = nameb('N')
	Ownership   = nameb('K')
	OwnerDigest = nameb('D')

	// blocks
	BlockData = nameb('B')

	// just for testing
	TestData = nameb('Z')
)

Names of the pools

Variables

This section is empty.

Functions

func Finalise

func Finalise()

close the database connection

func Initialise

func Initialise(database string)

open up the database connection

this must be called before any pool.New() is created

Types

type Batch added in v0.1.2

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

type for batch operations

func NewBatch added in v0.1.2

func NewBatch() *Batch

begin a new batch of Adds and Removes

the adds and removes will be executed only on Commit

func (*Batch) Add added in v0.1.2

func (batch *Batch) Add(pool *Pool, key []byte, value []byte)

add a key/value bytes pair to the database

func (*Batch) Commit added in v0.1.2

func (batch *Batch) Commit()

commit the accumulated Adds and removes to the database

func (*Batch) Remove added in v0.1.2

func (batch *Batch) Remove(pool *Pool, key []byte)

remove a key from the database

type Element

type Element struct {
	Key   []byte
	Value []byte
}

a binary data item

type FetchCursor

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

cursor structure

func (*FetchCursor) Fetch

func (cursor *FetchCursor) Fetch(count int) ([]Element, error)

fetch some elements starting from key

func (*FetchCursor) Seek

func (cursor *FetchCursor) Seek(key []byte) *FetchCursor

type IndexedPool

type IndexedPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

the pool handle

func NewIndexed

func NewIndexed(prefix nameb) *IndexedPool

create a new indexed pool with a specific key prefix

Separate indexes are created to provide a timestamp ordering

func (*IndexedPool) Add

func (p *IndexedPool) Add(key []byte, value []byte) (bool, error)

add a key/value bytes pair to the database

func (*IndexedPool) Flush

func (p *IndexedPool) Flush() error

flush any unsaved data

func (*IndexedPool) Get

func (p *IndexedPool) Get(key []byte) ([]byte, error)

read a value for a given key

func (*IndexedPool) Recent

func (p *IndexedPool) Recent(start *gnomon.Cursor, count int, convert func(key []byte, value []byte) interface{}) ([]interface{}, *gnomon.Cursor, error)

fetch the N most recent string key and data pairs

func (*IndexedPool) Remove

func (p *IndexedPool) Remove(key []byte) error

remove a key from the database

type Iterator

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

func (*Iterator) Next

func (it *Iterator) Next() *Element

func (*Iterator) Release

func (it *Iterator) Release()

must release the iterator when finished with it

type Pool

type Pool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

the pool handle

func New

func New(prefix nameb) *Pool

create a new pool with a specific key prefix

func (*Pool) Add

func (p *Pool) Add(key []byte, value []byte)

add a key/value bytes pair to the database

func (*Pool) Flush

func (p *Pool) Flush()

flush the pool channel

func (*Pool) Get

func (p *Pool) Get(key []byte) []byte

read a value for a given key

this returns the actual element - copy the result if it must be preserved

func (*Pool) Has added in v0.1.2

func (p *Pool) Has(key []byte) bool

Check if a key exists

func (*Pool) Iterate

func (p *Pool) Iterate(key []byte) *Iterator

fetch some elements starting from key

func (*Pool) LastElement

func (p *Pool) LastElement() (Element, bool)

get the last element in a pool

func (*Pool) NewFetchCursor

func (p *Pool) NewFetchCursor() *FetchCursor

initialise a cursor to the start of a key range

func (*Pool) Remove

func (p *Pool) Remove(key []byte)

remove a key from the database

Jump to

Keyboard shortcuts

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