Documentation ¶
Overview ¶
Package cdb provides interfaces for a data structure of the Constant Database proposed by Daniel J. Bernstein http://cr.yp.to/cdb.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyCDB = errors.New("cdb is empty")
var ErrEntryNotFound = errors.New("cdb entry not found")
EntryDoesNotExists could be returned for Get method is cdb has no such key
var ErrOutOfMemory = errors.New("OutOfMemory. CDB can handle any database up to 4 gigabytes")
ErrOutOfMemory tells that it was an attempt to create a cdb database up to 4 gigabytes
Functions ¶
Types ¶
type CDB ¶
type CDB struct {
Hasher
}
CDB is an associative array: it maps strings (“keys”) to strings (“data”).
func (*CDB) GetWriter ¶
func (cdb *CDB) GetWriter(writer io.WriteSeeker) (Writer, error)
GetWriter returns a new Writer object.
func (*CDB) SetHash ¶
SetHash tells the cdb to use the given hash function for calculations. Given hash will be used only for new instances of Reader, Writer.
h := cdb.New() h.GetWriter(f) ... do some work ( here we use default Hasher ) h.SetHash(fnv.Hash32) h.GetReader(f) - only new instances will be use fnv.Hash32
type Iterator ¶
type Iterator interface { // Next moves the iterator to the next record. Returns true on success otherwise returns false. Next() (bool, error) // Record returns the current record. This method is lazy. It means, a data is read on require. Record() Record // HasNext tells if the iterator can be moved to the next record. HasNext() bool // Key returns key's []byte slice. It is usually easier to use and // faster then iterator.Record().Key(). // Because it doesn't requiers allocation for record copy. Key() ([]byte, error) // ValueBytes returns values's []byte slice. It is usually easier to use and // faster then iterator.Record().Key(). // Because it doesn't requiers allocation for record copy. Value() ([]byte, error) }
Iterator provides API for iterating through database's records. Do not share object between multiple goroutines.
type Reader ¶
type Reader interface { // Get returns the first value associated with the given key Get(key []byte) ([]byte, error) // Has returns true if the given key exists, otherwise returns false. Has(key []byte) (bool, error) // Iterator returns a new Iterator object that points on the first record. Iterator() (Iterator, error) // IteratorAt returns a new Iterator object that points on the first record associated with the given key. IteratorAt(key []byte) (Iterator, error) // Size returns the size of the dataset Size() int }
Reader provides API for retrieving values, iterating through dataset. All methods are thread safe.