Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultCompare(a, b Key) int
- func MarshalHint(hint Hint) []byte
- func Ranges(it Iterator, handle func(hint Hint) error) error
- type BTree
- type BTreeIterator
- type BTreeN
- func (b *BTreeN) Clear()
- func (b *BTreeN) Close() error
- func (b *BTreeN) Compare(k1, k2 Key) int
- func (b *BTreeN) Del(ks ...Key) error
- func (b *BTreeN) Get(key Key) (Hint, bool)
- func (b *BTreeN) Iterator(opt RangeOption) (Iterator, error)
- func (b *BTreeN) Put(hs ...Hint) error
- func (b *BTreeN) Size() int
- type Compare
- type Hint
- type Index
- type Iterator
- type Key
- type RangeOption
Constants ¶
const ( Less = -1 + iota Equal Greater )
const MaxHintHeaderSize = binary.MaxVarintLen32*2 + binary.MaxVarintLen64*2
MaxHintHeaderSize +-----+-------+--------+------+------+ | fid | block | offset | ttl | key | +-----+-------+--------+------+------+ | 5 B | 5 B | 10 B | 10 B | auto | +-----+-------+--------+------+------+
Variables ¶
var ( ErrNilIterator = errors.New("nil iterator") ErrClosed = errors.New("index closed") )
Functions ¶
func DefaultCompare ¶
func MarshalHint ¶
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 ¶
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
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 ¶
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 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.