Documentation
¶
Overview ¶
Package bptree implements an on-disk B+ tree indexing scheme that can store key-value pairs and provide fast lookups and range scans. keys can be blobs binary data and value is uint64.
Index ¶
- func Print(tree *BPlusTree) error
- type BPlusTree
- func (tree *BPlusTree) Close() error
- func (tree *BPlusTree) Del(key []byte) (uint64, error)
- func (tree *BPlusTree) Get(key []byte) (uint64, error)
- func (tree *BPlusTree) Put(key []byte, val uint64) error
- func (tree *BPlusTree) Scan(key []byte, reverse bool, scanFn func(key []byte, v uint64) bool) error
- func (tree *BPlusTree) Size() int64
- func (tree *BPlusTree) String() string
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BPlusTree ¶
type BPlusTree struct {
// contains filtered or unexported fields
}
BPlusTree represents an on-disk B+ tree. Each node in the tree is mapped to a single page in the file. Degree of the tree is decided based on the page size and max key size while initializing.
func Open ¶
Open opens the named file as a B+ tree index file and returns an instance B+ tree for use. Use ":memory:" for an in-memory B+ tree instance for quick testing setup. Degree of the tree is computed based on maxKeySize and pageSize used by the pager. If nil options are provided, defaultOptions will be used.
func (*BPlusTree) Del ¶
Del removes the key-value entry from the B+ tree. If the key does not exist, returns error.
func (*BPlusTree) Get ¶
Get fetches the value associated with the given key. Returns error if key not found.
func (*BPlusTree) Put ¶
Put puts the key-value pair into the B+ tree. If the key already exists, its value will be updated.
func (*BPlusTree) Scan ¶
Scan performs an index scan starting at the given key. Each entry will be passed to the scanFn. If the key is zero valued (nil or len=0), then the left/right leaf key will be used as the starting key. Scan continues until the right most leaf node is reached or the scanFn returns 'true' indicating to stop the scan. If reverse=true, scan starts at the right most node and executes in descending order of keys.
type Options ¶
type Options struct { // ReadOnly mode for index. All mutating operations will return // error in this mode. ReadOnly bool // FileMode for creating the file. Applicable only if when a new // index file is being initialized. FileMode os.FileMode // PageSize to be for file I/O. All reads and writes will always // be done with pages of this size. Must be multiple of 4096. PageSize int // MaxKeySize represents the maximum size allowed for the key. // Put call with keys larger than this will result in error. // Branching factor reduces as this size increases. So smaller // the better. MaxKeySize int // PreAlloc can be set to enable pre-allocating pages when the // index is initialized. This helps avoid mmap/unmap and truncate // overheads during insertions. PreAlloc int }
Options represents the configuration options for the B+ tree index.