Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosed = errors.New("shelf closed") ErrOversized = errors.New("data too large for shelf") ErrBadIndex = errors.New("bad index") ErrEmptyData = errors.New("empty data") ErrReadonly = errors.New("read-only mode") ErrCorruptData = errors.New("corrupt data") )
var ( Magic = [5]byte{'b', 'i', 'l', 'l', 'y'} ShelfHeaderSize = binary.Size(shelfHeader{}) )
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface { io.Closer // Put stores the data to the underlying database, and returns the key needed // for later accessing the data. // The data is copied by the database, and is safe to modify after the method returns Put(data []byte) (uint64, error) // Get retrieves the data stored at the given key. Get(key uint64) ([]byte, error) // Delete marks the data for deletion, which means it will (eventually) be // overwritten by other data. After calling Delete with a given key, the results // from doing Get(key) is undefined -- it may return the same data, or some other // data, or fail with an error. Delete(key uint64) error // Size returns the storage size of the value belonging to the given key. Size(key uint64) uint32 // Limits returns the smallest and largest slot size. Limits() (uint32, uint32) // Infos retrieves various internal statistics about the database. Infos() *Infos // Iterate iterates through all the data in the database, and invokes the // given onData method for every element Iterate(onData OnDataFn) error }
Database represents a `billy` storage.
func Open ¶
func Open(opts Options, slotSizeFn SlotSizeFn, onData OnDataFn) (Database, error)
Open opens a (new or existing) database, with configurable limits. The given slotSizeFn will be used to determine both the shelf sizes and the number of shelves. The function must yield values in increasing order.
If shelf already exists, they are opened and read, in order to populate the internal gap-list. While doing so, it's a good opportunity for the caller to read the data out, (which is probably desirable), which can be done using the optional onData callback.
type Infos ¶
type Infos struct {
Shelves []*ShelfInfos
}
Infos contains a set of statistics about the underlying datastore.
type OnDataFn ¶
OnDataFn is used to iterate the entire dataset in the database. After the method returns, the content of 'data' will be modified by the iterator, so it needs to be copied if it is to be used later.
type ShelfInfos ¶
ShelfInfos contains some statistics about the data stored in a single shelf.
type SlotSizeFn ¶
SlotSizeFn is a method that acts as a "generator": a closure which, at each invocation, should spit out the next slot-size. In order to create a database with three shelves invocation of the method should return e.g.
10, false 20, false 30, true
OBS! The slot size must take item header size (4 bytes) into account. So if you plan to store 120 bytes, then the slot needs to be at least 124 bytes large.
func SlotSizeLinear ¶
func SlotSizeLinear(size, count int) SlotSizeFn
SlotSizeLinear is a SlotSizeFn which arranges the slots in shelves which increase linearly.
func SlotSizePowerOfTwo ¶
func SlotSizePowerOfTwo(min, max uint32) SlotSizeFn
SlotSizePowerOfTwo is a SlotSizeFn which arranges the slots in shelves which double in size for each level.