ixkey

package
v0.0.0-...-f022186 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ixkey handles specifying and encoding index key strings that are directly comparable. Single field index keys are not encoded. But a single value for a multi-field index still needs to be encoded. Fields are separated by two zero bytes 0,0. Zero bytes are encoded as 0,1. Normally the values will be packed, but this is not required as long as they compare directly. If a resulting entry is longer than maxEntry it will panic.

Index

Constants

View Source
const Max = "\xff\xff\xff\xff\xff\xff\xff\xff"
View Source
const Min = ""
View Source
const Sep = "\x00\x00"

Variables

This section is empty.

Functions

func Cklen

func Cklen(s string) string

func Cksize

func Cksize(n int)

func Decode

func Decode(comp string) []string

Decode is for tests and debugging

func DecodeValues

func DecodeValues(comp string) []Value

func Encode

func Encode(s string) string

func HasPrefix

func HasPrefix(s, prefix string) bool

HasPrefix is prefix by field. i.e. the prefix must be followed by a field separator (or at the end)

func Make

func Make(row Row, hdr *Header, cols []string, th *Thread, st *SuTran) string

Make builds a key for cols from a Row and Header

Types

type Encoder

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

Encoder builds keys incrementally. Zero value is ready to use. Note: Do not use this for single field keys - they should not be encoded.

func (*Encoder) Add

func (e *Encoder) Add(fld string)

Add appends a field value

func (*Encoder) Dup

func (e *Encoder) Dup() *Encoder

func (*Encoder) String

func (e *Encoder) String() string

String returns the key and resets the Encoder to be empty. Trailing field separators (empty fields) are trimmed.

type Spec

type Spec struct {
	// Fields specifies the fields in the key.
	Fields []int
	// Fields2 is used for unique indexes (that allow multiple empty keys).
	// It will only be used if all of the Fields value are empty.
	Fields2 []int
}

Spec specifies the field(s) in an index key

func (*Spec) Compare

func (spec *Spec) Compare(r1, r2 Record) int

Compare compares the specified fields of the two records without building keys for them

func (*Spec) Encodes

func (spec *Spec) Encodes() bool

Encodes returns whether the Spec requires encoding.

func (*Spec) Key

func (spec *Spec) Key(rec Record) string

Key builds a key from a data Record using a Spec.

func (*Spec) String

func (spec *Spec) String() string

func (*Spec) Trunc

func (spec *Spec) Trunc(n int) *Spec

Trunc returns a new Spec with Fields shortened to n fields. n must be less than len(fields). Fields2 is dropped.

Jump to

Keyboard shortcuts

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