Documentation
¶
Overview ¶
Package index has the order-preserving key encoding and the in-memory secondary index (a B-tree of key + id). Segment indexes (M04) implement the same Index interface.
Index ¶
- Constants
- func CheckName(name string) error
- func Compound(name string) bool
- func DocKeys(doc map[string]any, name, timeField string) [][]byte
- func Encode(v query.Value) []byte
- func Fields(name string) []string
- func Keys(doc map[string]any, path string, isTime bool) [][]byte
- func PrefixEnd(prefix []byte) []byte
- type Index
- type Mem
- type Range
Constants ¶
const ( // MaxFields is the most fields of one compound index. MaxFields = 4 // MaxTupleKeys is the most keys one document may have in one compound // index (the pairs of the elements of its arrays). MaxTupleKeys = 1024 )
Variables ¶
This section is empty.
Functions ¶
func CheckName ¶ added in v1.20.0
CheckName tells if name is a valid index name: one field, or 2 to MaxFields different fields. The id field is not allowed in a compound index (every key ends with the id already).
func DocKeys ¶ added in v1.20.0
DocKeys are the keys of doc in the index name: Keys for one field, the tuple keys for a compound index. timeField is the time field of the collection ("" for none).
func Encode ¶
Encode returns bytes that sort like query.Compare. The encoding is prefix-free, so key + id never mixes with a longer key.
number: tag + 8 bytes (float64 bits, flipped so bytes sort as numbers) time: tag + 8 bytes (unix nanoseconds, sign bit flipped) string, object, array: tag + bytes with 0x00 → 0x00 0xFF, then 0x00 0x01
Types ¶
type Index ¶
type Index interface {
// Ascend calls fn with each id in key order until fn returns false.
Ascend(r Range, fn func(id string) bool)
Len() int
}
Index answers range lookups with document ids.
type Mem ¶
type Mem struct {
// contains filtered or unexported fields
}
Mem is the memtable index. It is not safe for concurrent use: the collection locks around it.
type Range ¶
Range is a span of encoded keys. A nil bound is open.
func Cmp ¶
Cmp is the range of $gt, $gte, $lt or $lte. Comparisons stay inside the type of v, like the evaluator does.
func Intersect ¶ added in v1.20.0
Intersect is the keys in both a and b. Both are ranges of tuples: the low end is in, the high end is out (as PrefixRange and TupleCmp give them).
func Overflow ¶ added in v1.20.0
func Overflow() Range
Overflow is the range of the overflow documents of a compound index.
func PrefixRange ¶ added in v1.20.0
PrefixRange is the range of the tuples that start with prefix.