index

package
v0.0.0-...-473e3f1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Indexer

type Indexer interface {
	// Put key and position into the index.
	Put(key []byte, position *wal.ChunkPosition) *wal.ChunkPosition

	// Get the position of the key in the index.
	Get(key []byte) *wal.ChunkPosition

	// Delete the index of the key.
	Delete(key []byte) (*wal.ChunkPosition, bool)

	// Size represents the number of keys in the index.
	Size() int

	// Ascend iterates over items in ascending order and invokes the handler function for each item.
	// If the handler function returns false, iteration stops.
	Ascend(handleFn func(key []byte, position *wal.ChunkPosition) (bool, error))

	// AscendRange iterates in ascending order within [startKey, endKey], invoking handleFn.
	// Stops if handleFn returns false.
	AscendRange(startKey, endKey []byte, handleFn func(key []byte, position *wal.ChunkPosition) (bool, error))

	// AscendGreaterOrEqual iterates in ascending order, starting from key >= given key,
	// invoking handleFn. Stops if handleFn returns false.
	AscendGreaterOrEqual(key []byte, handleFn func(key []byte, position *wal.ChunkPosition) (bool, error))

	// Descend iterates over items in descending order and invokes the handler function for each item.
	// If the handler function returns false, iteration stops.
	Descend(handleFn func(key []byte, pos *wal.ChunkPosition) (bool, error))

	// DescendRange iterates in descending order within [startKey, endKey], invoking handleFn.
	// Stops if handleFn returns false.
	DescendRange(startKey, endKey []byte, handleFn func(key []byte, position *wal.ChunkPosition) (bool, error))

	// DescendLessOrEqual iterates in descending order, starting from key <= given key,
	// invoking handleFn. Stops if handleFn returns false.
	DescendLessOrEqual(key []byte, handleFn func(key []byte, position *wal.ChunkPosition) (bool, error))
}

Indexer is an interface for indexing key and position. It is used to store the key and the position of the data in the WAL. The index will be rebuilt when the database is opened. You can implement your own indexer by implementing this interface.

func NewIndexer

func NewIndexer() Indexer

type IndexerType

type IndexerType = byte
const (
	BTree IndexerType = iota
)

type MemoryBTree

type MemoryBTree struct {
	// contains filtered or unexported fields
}

MemoryBTree is a memory based btree implementation of the Index interface It is a wrapper around the google/btree package: github.com/google/btree

func (*MemoryBTree) Ascend

func (mt *MemoryBTree) Ascend(handleFn func(key []byte, position *wal.ChunkPosition) (bool, error))

func (*MemoryBTree) AscendGreaterOrEqual

func (mt *MemoryBTree) AscendGreaterOrEqual(
	key []byte,
	handleFn func(key []byte, position *wal.ChunkPosition) (bool, error),
)

func (*MemoryBTree) AscendRange

func (mt *MemoryBTree) AscendRange(
	startKey, endKey []byte,
	handleFn func(key []byte, position *wal.ChunkPosition) (bool, error),
)

func (*MemoryBTree) Delete

func (mt *MemoryBTree) Delete(key []byte) (*wal.ChunkPosition, bool)

func (*MemoryBTree) Descend

func (mt *MemoryBTree) Descend(handleFn func(key []byte, pos *wal.ChunkPosition) (bool, error))

func (*MemoryBTree) DescendLessOrEqual

func (mt *MemoryBTree) DescendLessOrEqual(
	key []byte,
	handleFn func(key []byte, position *wal.ChunkPosition) (bool, error),
)

func (*MemoryBTree) DescendRange

func (mt *MemoryBTree) DescendRange(
	startKey, endKey []byte,
	handleFn func(key []byte, position *wal.ChunkPosition) (bool, error),
)

func (*MemoryBTree) Get

func (mt *MemoryBTree) Get(key []byte) *wal.ChunkPosition

func (*MemoryBTree) Put

func (mt *MemoryBTree) Put(key []byte, position *wal.ChunkPosition) *wal.ChunkPosition

func (*MemoryBTree) Size

func (mt *MemoryBTree) Size() int

Jump to

Keyboard shortcuts

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