index

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const BPlusTreeIndexFileName = "bplustree-index"

Variables

View Source
var DefaultIteratorOptions = IteratorOptions{
	Prefix:  nil,
	Reverse: false,
}

DefaultOptions default options of an iterator of an index

View Source
var IndexBucketName = []byte("baradb-index")

Functions

This section is empty.

Types

type Index

type Index interface {
	// Put stores a given key and its value in the index
	//
	// It may replaces the old value if the given already exists
	//
	// It returns the old value if the given key already exists and nil otherwise
	Put([]byte, *data.LogRecordPosition) *data.LogRecordPosition

	// Get returns the value of the given key from the index
	//
	// It returns a value if the given key already exists and nil otherwise
	Get([]byte) *data.LogRecordPosition

	// Delete deletes the value of the given key in the index
	//
	// It returns the deleted value and a boolean value true if the key exists
	// Otherwise, it returns nil and a boolean value false
	Delete([]byte) (*data.LogRecordPosition, bool)

	// Size returns how many key/value pairs in the index
	Size() int

	// Iterator creates an iterator of the index
	//
	// The iterator supports reversed iteration if the given boolean value is true
	Iterator(bool) Iterator

	// Close closes the index
	Close() error
}

Index repersents abstract interface of an in-memory index

An index stores key/value pairs. A key is the key of a log record, and a value is a log record's position in a data file in a disk.

func New

func New(t IndexType, d string, syncWrites bool) Index

New A simple factory menthod for creating an index

type IndexType

type IndexType = int8

IndexType enum

const (
	Btree  IndexType = iota + 1 // Btree B Tree index
	ARtree                      // ARtree Adaptive Radix Tree index
	BPtree                      // BPtree B+ Tree index
)

type Iterator

type Iterator interface {
	Rewind() // Rewind resets the iteration

	Seek([]byte)

	Next()

	Valid() bool

	Key() []byte

	Value() *data.LogRecordPosition

	Close() // Close closes the iterator
}

An abstract interator of an index

type IteratorOptions

type IteratorOptions struct {
	Prefix  []byte // Traverses an iterator's keys with a specified non-nil prefix
	Reverse bool   // Traverses an iterator reversely if true
}

Options options of an iterator of an index

Jump to

Keyboard shortcuts

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