Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FastPrefixFormatter ¶ added in v1.0.1
type FastPrefixFormatter struct {
// contains filtered or unexported fields
}
Prefixes a single byte before a 32 byte hash.
func NewFastPrefixFormatter ¶ added in v1.0.1
func NewFastPrefixFormatter(prefix byte, length int) *FastPrefixFormatter
func (*FastPrefixFormatter) Key ¶ added in v1.0.1
func (f *FastPrefixFormatter) Key(bz []byte) []byte
func (*FastPrefixFormatter) KeyInt64 ¶ added in v1.0.1
func (f *FastPrefixFormatter) KeyInt64(bz int64) []byte
func (*FastPrefixFormatter) Length ¶ added in v1.0.1
func (f *FastPrefixFormatter) Length() int
func (*FastPrefixFormatter) Prefix ¶ added in v1.0.1
func (f *FastPrefixFormatter) Prefix() []byte
func (*FastPrefixFormatter) Scan ¶ added in v1.0.1
func (f *FastPrefixFormatter) Scan(key []byte, a interface{})
type KeyFormat ¶
type KeyFormat struct {
// contains filtered or unexported fields
}
Provides a fixed-width lexicographically sortable []byte key format
func NewKeyFormat ¶
Create a []byte key format based on a single byte prefix and fixed width key segments each of whose length is specified by by the corresponding element of layout.
For example, to store keys that could index some objects by a version number and their SHA256 hash using the form: 'c<version uint64><hash [32]byte>' then you would define the KeyFormat with:
var keyFormat = NewKeyFormat('c', 8, 32)
Then you can create a key with:
func ObjectKey(version uint64, objectBytes []byte) []byte { hasher := sha256.New() hasher.Sum(nil) return keyFormat.Key(version, hasher.Sum(nil)) }
If the last term of the layout is 0 it is unbounded, and will accept any length.
NewKeyFormat panics if any other term than the last is 0.
func (*KeyFormat) Key ¶
Format the args passed into the key format - will panic if the arguments passed do not match the length of the segment to which they correspond. When called with no arguments returns the raw prefix (useful as a start element of the entire keys space when sorted lexicographically).
func (*KeyFormat) KeyBytes ¶
Format the byte segments into the key format - will panic if the segment lengths do not match the layout.