pool

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2016 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

maintain a memory pool of a number of elements

This maintains an in memory LRU list upto a fixed number of elements and permanently store the data in LevelDB.

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
	OwnerIndex = nameb('O')

	// 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 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 an optional local memory cache

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

create empty index and LRU cache

func (*Pool) Get

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

read a value for a given key

this returns the actual element - copy it if you need to returns "found" as boolean

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