keys

package
v0.15.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IteratorFromRange

func IteratorFromRange[K Key](store sdk.KVStore, r Range[K]) (iter sdk.Iterator, prefixBytes []byte)

IteratorFromRange returns a sdk.Iterator given the range and the sdk.KVStore to apply the iterator to. prefixBytes MUST not be mutated.

Types

type Bound

type Bound[K Key] struct {
	// contains filtered or unexported fields
}

Bound defines a key bound.

func Exclusive

func Exclusive[K Key](k K) Bound[K]

Exclusive creates a key Bound which is exclusive, which means the provided key will be excluded from the key range.

func Inclusive

func Inclusive[K Key](k K) Bound[K]

Inclusive creates a key Bound which is inclusive, which means the provided key will be included in the key range (if present).

type Key

type Key interface {
	// KeyBytes returns the key as bytes.
	KeyBytes() []byte
	// FromKeyBytes parses the Key from bytes.
	// returns i which is the numbers of bytes read from the buffer.
	// Constraint: Key == Self (aka the interface implementer).
	// NOTE(mercilex): we in theory should return Key[T any] and constrain
	// in the collections.Map, collections.IndexedMap, collections.Set
	// that T is in fact the Key itself.
	// We don't do it otherwise all our APIs would get messy
	// due to golang's compiler type inference.
	FromKeyBytes(buf []byte) (i int, k Key)
	// Stringer is implemented to allow human-readable formats, especially important in errors.
	fmt.Stringer
}

Key defines a type which can be converted to and from bytes. Constraints:

  • It's ordered, meaning, for example: StringKey("a").KeyBytes() < StringKey("b").KeyBytes(). Int64Key(100).KeyBytes() > Int64Key(-100).KeyBytes()
  • Going back and forth using KeyBytes and FromKeyBytes produces the same results.
  • It's prefix safe, meaning that bytes.Contains(StringKey("a").KeyBytes(), StringKey("aa").KeyBytes()) = false.

type Order

type Order uint8

Order defines the ordering of keys.

const (
	// OrderAscending defines an order going from the
	// smallest key to the biggest key.
	OrderAscending Order = iota
	// OrderDescending defines an order going from the
	// biggest key to the smallest. In the KVStore
	// it equals to iterating in reverse.
	OrderDescending
)

type Pair

type Pair[K1 Key, K2 Key] struct {
	// contains filtered or unexported fields
}

Pair represents a multipart key composed of two Key of different or equal types.

func Join

func Join[K1 Key, K2 Key](k1 K1, k2 K2) Pair[K1, K2]

Join joins the two parts of a Pair key.

func PairPrefix

func PairPrefix[K1 Key, K2 Key](k1 K1) Pair[K1, K2]

PairPrefix is used to provide only the K1 part of the Pair. Usually used in Range.Prefix where Key is Pair.

func PairSuffix

func PairSuffix[K1 Key, K2 Key](k2 K2) Pair[K1, K2]

PairSuffix is used to provide only the K2 part of the Pair. Usually used in Range.Start or Range.End where Key is Pair.

func (Pair[K1, K2]) FromKeyBytes

func (t Pair[K1, K2]) FromKeyBytes(b []byte) (int, Key)

func (Pair[K1, K2]) K1

func (t Pair[K1, K2]) K1() K1

K1 returns the first part of the key, if present. If the key is not present the zero value is returned.

func (Pair[K1, K2]) K2

func (t Pair[K1, K2]) K2() K2

K2 returns the second part of the key, if present, If the key is not present the zero value is returned.

func (Pair[K1, K2]) KeyBytes

func (t Pair[K1, K2]) KeyBytes() []byte

func (Pair[K1, K2]) String

func (t Pair[K1, K2]) String() string

type PairRange

type PairRange[K1, K2 Key] struct {
	// contains filtered or unexported fields
}

PairRange implements the Range interface to provide an easier way to range over Pair keys.

func (PairRange[K1, K2]) Descending

func (p PairRange[K1, K2]) Descending() PairRange[K1, K2]

func (PairRange[K1, K2]) EndExclusive

func (p PairRange[K1, K2]) EndExclusive(end K2) PairRange[K1, K2]

func (PairRange[K1, K2]) EndInclusive

func (p PairRange[K1, K2]) EndInclusive(end K2) PairRange[K1, K2]

func (PairRange[K1, K2]) Prefix

func (p PairRange[K1, K2]) Prefix(prefix K1) PairRange[K1, K2]

func (PairRange[K1, K2]) RangeValues

func (p PairRange[K1, K2]) RangeValues() (prefix *Pair[K1, K2], start *Bound[Pair[K1, K2]], end *Bound[Pair[K1, K2]], order Order)

func (PairRange[K1, K2]) StartExclusive

func (p PairRange[K1, K2]) StartExclusive(start K2) PairRange[K1, K2]

func (PairRange[K1, K2]) StartInclusive

func (p PairRange[K1, K2]) StartInclusive(start K2) PairRange[K1, K2]

type Range

type Range[K Key] interface {
	// RangeValues returns the range instructions.
	RangeValues() (prefix *K, start *Bound[K], end *Bound[K], order Order)
}

Range defines an interface which instructs on how to iterate over keys.

type RawRange

type RawRange[K Key] struct {
	// contains filtered or unexported fields
}

RawRange is a Range implementer.

func NewRange

func NewRange[K Key]() RawRange[K]

NewRange returns a Range instance which iterates over all keys in ascending order.

func (RawRange[K]) Descending

func (r RawRange[K]) Descending() RawRange[K]

Descending sets the key range to be inverse.

func (RawRange[K]) End

func (r RawRange[K]) End(bound Bound[K]) RawRange[K]

End sets the end range of the key.

func (RawRange[K]) Prefix

func (r RawRange[K]) Prefix(key K) RawRange[K]

Prefix sets a fixed prefix for the key range.

func (RawRange[K]) RangeValues

func (r RawRange[K]) RangeValues() (prefix *K, start *Bound[K], end *Bound[K], order Order)

func (RawRange[K]) Start

func (r RawRange[K]) Start(bound Bound[K]) RawRange[K]

Start sets the start range of the key.

type StringKey

type StringKey string

func String

func String[T ~string](v T) StringKey

String converts any member of the string typeset into a StringKey NOTE(mercilex): this exists to avoid type errors in which bytes are being converted to a StringKey which is not correct behavior.

func (StringKey) FromKeyBytes

func (s StringKey) FromKeyBytes(b []byte) (int, Key)

func (StringKey) KeyBytes

func (s StringKey) KeyBytes() []byte

func (StringKey) Marshal

func (s StringKey) Marshal() ([]byte, error)

func (StringKey) String

func (s StringKey) String() string

func (*StringKey) Unmarshal

func (s *StringKey) Unmarshal(b []byte) error

type Uint64Key

type Uint64Key uint64

func Uint64

func Uint64[T ~uint64](u T) Uint64Key

func (Uint64Key) FromKeyBytes

func (u Uint64Key) FromKeyBytes(b []byte) (i int, k Key)

func (Uint64Key) KeyBytes

func (u Uint64Key) KeyBytes() []byte

func (Uint64Key) Marshal

func (u Uint64Key) Marshal() ([]byte, error)

func (Uint64Key) String

func (u Uint64Key) String() string

func (*Uint64Key) Unmarshal

func (u *Uint64Key) Unmarshal(b []byte) error

type Uint8Key

type Uint8Key uint8

func (Uint8Key) FromKeyBytes

func (u Uint8Key) FromKeyBytes(b []byte) (i int, k Key)

func (Uint8Key) KeyBytes

func (u Uint8Key) KeyBytes() []byte

func (Uint8Key) Marshal

func (u Uint8Key) Marshal() ([]byte, error)

func (Uint8Key) String

func (u Uint8Key) String() string

func (*Uint8Key) Unmarshal

func (u *Uint8Key) Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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