index

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Less = -1 + iota
	Equal
	Greater
)
View Source
const MaxHintHeaderSize = binary.MaxVarintLen32*2 + binary.MaxVarintLen64*2

MaxHintHeaderSize +-----+-------+--------+------+------+ | fid | block | offset | ttl | key | +-----+-------+--------+------+------+ | 5 B | 5 B | 10 B | 10 B | auto | +-----+-------+--------+------+------+

Variables

View Source
var (
	ErrNilIterator = errors.New("nil iterator")
	ErrClosed      = errors.New("index closed")
)

Functions

func DefaultCompare

func DefaultCompare(a, b Key) int

func MarshalHint

func MarshalHint(hint Hint) []byte

func Ranges added in v0.2.0

func Ranges(it Iterator, handle func(hint Hint) error) error

Types

type BTree

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

BTree is btree implementation of Index that allows the actions of finding data, sequential access, inserting data, and deleting to be done in O(log n) time

func BtreeIndex

func BtreeIndex(degree int, compare Compare) *BTree

func (*BTree) Clear added in v0.2.0

func (b *BTree) Clear()

func (*BTree) Close

func (b *BTree) Close() error

func (*BTree) Compare

func (b *BTree) Compare(k1, k2 Key) int

func (*BTree) Del

func (b *BTree) Del(ks ...Key) error

func (*BTree) Get

func (b *BTree) Get(key Key) (Hint, bool)

func (*BTree) Iterator

func (b *BTree) Iterator(opt RangeOption) (Iterator, error)

func (*BTree) Put

func (b *BTree) Put(hs ...Hint) error

func (*BTree) Size

func (b *BTree) Size() int

type BTreeIterator

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

func (*BTreeIterator) HasNext added in v0.2.0

func (b *BTreeIterator) HasNext() bool

func (*BTreeIterator) Hint added in v0.2.0

func (b *BTreeIterator) Hint() *Hint

func (*BTreeIterator) Next

func (b *BTreeIterator) Next()

func (*BTreeIterator) Rewind

func (b *BTreeIterator) Rewind()

type BTreeN added in v0.2.2

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

BTreeN btree with no lock

func BtreeNIndex added in v0.2.2

func BtreeNIndex(degree int, compare Compare) *BTreeN

func (*BTreeN) Clear added in v0.2.2

func (b *BTreeN) Clear()

func (*BTreeN) Close added in v0.2.2

func (b *BTreeN) Close() error

func (*BTreeN) Compare added in v0.2.2

func (b *BTreeN) Compare(k1, k2 Key) int

func (*BTreeN) Del added in v0.2.2

func (b *BTreeN) Del(ks ...Key) error

func (*BTreeN) Get added in v0.2.2

func (b *BTreeN) Get(key Key) (Hint, bool)

func (*BTreeN) Iterator added in v0.2.2

func (b *BTreeN) Iterator(opt RangeOption) (Iterator, error)

func (*BTreeN) Put added in v0.2.2

func (b *BTreeN) Put(hs ...Hint) error

func (*BTreeN) Size added in v0.2.2

func (b *BTreeN) Size() int

type Compare

type Compare func(a, b Key) int

Compare returns a function that decide how to compare keys

type Hint

type Hint struct {
	wal.ChunkPos
	TTL int64
	Key Key

	// it will be ignored when marshalling and unmarshalling.
	// Meta only used in runtime, it will never be persisted to the database,
	// to save memory, do not stored big data in this field.
	Meta any
}

Hint represents a kev hint data

func UnMarshalHint

func UnMarshalHint(rawdata []byte) Hint

type Index

type Index interface {
	// Get returns the entry matching the given key
	// if not exist, returns zero-value, false
	Get(key Key) (Hint, bool)
	// Put inserts a new hint into the index, replace it if already exists
	Put(hs ...Hint) error
	// Del deletes the entry that matching the given key from the index
	Del(ks ...Key) error
	// Size return num of all hints in index
	Size() int
	// Iterator returns an iterator of index snapshots at a certain moment
	Iterator(opt RangeOption) (Iterator, error)
	// Close releases the resources and close indexer
	Close() error
	// Compare returns -1-less, 0-equal, 1-greater
	Compare(k1, k2 Key) int
	// Clear clears all the hints from index
	Clear()
}

Index storage a set of index hints and define index operation apis that implemented by concrete data struct.

type Iterator

type Iterator interface {
	// Rewind set cursor to the head of hints snapshots
	Rewind()
	Next()
	HasNext() bool
	Hint() *Hint
}

Iterator record snapshot of index hints at a certain moment, iterate them in the given order by cursor depending on the implementation of indexer, the behavior of iterator may be different, like hashmap or btree

type Key

type Key = []byte

type RangeOption

type RangeOption struct {
	// min key
	Min Key
	// max key
	Max Key
	// pattern matching
	Pattern Key
	// return order of elements, default is ascending
	Descend bool
}

RangeOption iterate over all keys in [min, max] with give order if min and max are nil, it will return all the keys in index, if min is nil and max is not nil, it will return the keys compare or equal than max, if max is nil and min is not nil, it will return the keys greater or equal than min, both of them are not nil, it will return the keys in range [min, max], then filter the keys with the give pattern if it is not empty. finally return these keys with the given order.

Jump to

Keyboard shortcuts

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