fast1

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: 0BSD Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fast1 implements the original KVO word-map storage format. Like MessagePack, Fast1 remains supported, with transition to Fast2 or Compact2 intended. Moving this implementation does not change its stored bytes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(m AnyFast1Map) string

Dump formats a Fast1 map and its nested values for inspection.

func HexString

func HexString(data []uint64) string

HexString formats packed words as hexadecimal text for inspection.

Types

type AnyFast1Map

type AnyFast1Map interface {
	Type() kvo.AnyType
	IsMissing() bool
	KeyCount() int
	Keys() []uint64
	KeySeq() iter.Seq[uint64]
	Get(key uint64) uint64
	GetAnyMap(key uint64) AnyFast1Map
	Packable() Packable
	Dump() string
}

AnyFast1Map gives read access to keys, word values, and nested maps in either a mutable or immutable record.

type AnyFast1Record

type AnyFast1Record interface {
	AnyRoot() AnyFast1Map
	Packable
}

AnyFast1Record gives read access to the root map and packed data.

type ImmutableMap

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

ImmutableMap is a read-only view of one object in a packed Fast1 record.

func (ImmutableMap) Dump

func (m ImmutableMap) Dump() string

Dump formats the map for inspection.

func (ImmutableMap) Get

func (m ImmutableMap) Get(key uint64) uint64

Get reads the word for key, returning zero if absent.

func (ImmutableMap) GetAnyMap

func (m ImmutableMap) GetAnyMap(key uint64) AnyFast1Map

GetAnyMap opens a child through the common read interface.

func (ImmutableMap) GetChildWord

func (m ImmutableMap) GetChildWord(child, key uint64) (uint64, bool)

GetChildWord reads a word from a known child map without constructing a typed view. The boolean reports presence of the child. A missing word reads as zero.

func (ImmutableMap) GetMap

func (m ImmutableMap) GetMap(key uint64) ImmutableMap

GetMap opens the child map at key.

func (ImmutableMap) IsMissing

func (m ImmutableMap) IsMissing() bool

IsMissing reports whether this map has no object.

func (ImmutableMap) Items

func (m ImmutableMap) Items() func(yield func(k, v uint64) bool)

Items iterates the object's key/value word pairs.

func (ImmutableMap) KeyCount

func (m ImmutableMap) KeyCount() int

KeyCount returns the number of keys in this object.

func (ImmutableMap) KeyModel

func (m ImmutableMap) KeyModel(key uint64) kvo.AnyType

KeyModel resolves the logical value type for key.

func (ImmutableMap) KeySeq

func (m ImmutableMap) KeySeq() iter.Seq[uint64]

KeySeq iterates the keys without copying them.

func (ImmutableMap) Keys

func (m ImmutableMap) Keys() []uint64

Keys returns the map's key words. Treat the underlying storage as immutable.

func (ImmutableMap) Packable

func (m ImmutableMap) Packable() Packable

Packable returns the enclosing packed record.

func (ImmutableMap) RecordData

func (m ImmutableMap) RecordData() ImmutableRecordData

RecordData returns the complete record that contains the map.

func (ImmutableMap) RecordWithThisRoot

func (m ImmutableMap) RecordWithThisRoot() ImmutableRecord

RecordWithThisRoot returns a record over the same packed data using this map's logical type.

func (ImmutableMap) Type

func (m ImmutableMap) Type() kvo.AnyType

Type returns the map's logical type.

type ImmutableObjectData

type ImmutableObjectData []uint64

ImmutableObjectData represents a single object within ImmutableRecordData. It can be a map, an array or a set. Could even be a string or a blob, but we'd lack the exact size info, and those are better represented as []byte.

func (ImmutableObjectData) KeyCount

func (m ImmutableObjectData) KeyCount() int

KeyCount returns the number of keys in this object.

func (ImmutableObjectData) MapGet

func (m ImmutableObjectData) MapGet(key uint64) uint64

MapGet looks up the stored word for key, returning zero if absent.

func (ImmutableObjectData) MapKeys

func (m ImmutableObjectData) MapKeys() []uint64

MapKeys returns the key portion of the packed object's words.

type ImmutableRecord

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

ImmutableRecord is a high-level interface to immutableRecordData, representing an immutable a tree of objects in a binary format suitable for storing on disk and optimized for random access.

func EmptyRecord

func EmptyRecord(rootType kvo.AnyType) ImmutableRecord

EmptyRecord returns an empty immutable record with the specified root type.

func LoadRecord

func LoadRecord(data []byte, rootType kvo.AnyType) ImmutableRecord

LoadRecord views packed bytes as a record with the supplied logical root type.

func (ImmutableRecord) AnyRoot

func (r ImmutableRecord) AnyRoot() AnyFast1Map

AnyRoot returns the root through the common map interface.

func (ImmutableRecord) Data

Data returns the underlying packed record words.

func (ImmutableRecord) Pack

Pack returns the underlying packed record words without re-encoding.

func (ImmutableRecord) Root

func (r ImmutableRecord) Root() ImmutableMap

Root returns the root object's read-only map.

type ImmutableRecordData

type ImmutableRecordData []uint64

ImmutableRecordData provides for random access to an immutable tree of objects stored in a binary format suitable for mmap'ing.

The format is as follows:

 record -> flags:32 count:32 (objectKind:4 offset:28 size:32)... object...

 object -> map | arrayOrSet | stringOrBlob

	map -> key1 ... keyN valueOrRef1 ... valueOrRefN  (N determined by map size; keys are sorted)
	arrayOrSet -> valueOrRef1 ... valueOrRefN  (N is determined by array/set size; set elements are sorted)
	stringOrBlob is just raw bytes  (this is why object directory stores sizes in bytes)

 valueOrRef -> uint:64 | subobject:64

	subobject -> inlineStringOrData:64 | objectRef:64
	  inlineStringOrData -> alwaysOne:1 zeros:4 byteCount:3 inlineBytes:[7]byte
	  objectRef -> alwaysZero:1 zeroes:31 objectIndex:32

Note that only maps are implements so far.

func EmptyImmutableRecordData

func EmptyImmutableRecordData() ImmutableRecordData

EmptyImmutableRecordData returns the packed representation of an empty record.

func LoadRecordData

func LoadRecordData(data []byte) ImmutableRecordData

LoadRecordData views the bytes as packed words without copying. Their length must be a multiple of eight.

func (ImmutableRecordData) Bytes

func (r ImmutableRecordData) Bytes() []byte

Bytes views the packed words as bytes without copying.

func (ImmutableRecordData) HexString

func (r ImmutableRecordData) HexString() string

HexString formats the packed words for inspection.

func (ImmutableRecordData) Object

Object returns the object at index i. An out-of-range index panics.

func (ImmutableRecordData) ObjectCount

func (r ImmutableRecordData) ObjectCount() int

ObjectCount reads the object count from the packed header.

func (ImmutableRecordData) Pack

Pack returns the underlying packed record words without re-encoding.

func (ImmutableRecordData) Record

func (data ImmutableRecordData) Record(rootType kvo.AnyType) ImmutableRecord

Record interprets the packed words using the supplied root type.

func (ImmutableRecordData) RootObject

RootObject returns object zero, or nil when the record contains no objects.

func (ImmutableRecordData) Uints

func (r ImmutableRecordData) Uints() []uint64

Uints returns the underlying word slice. Treat it as read-only.

type List

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

TODO

type MutableMap

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

MutableMap allows mutating a map within a MutableRecord.

func NewRecord

func NewRecord(rootType kvo.AnyType) MutableMap

NewRecord sets up an empty mutable record with the given root model and an empty root map, and returns the root map.

func UpdateRecord

func UpdateRecord(orig ImmutableRecord) MutableMap

UpdateRecord sets up a mutable variant of the given record and returns its root map.

Example
package main

import (
	"fmt"

	"github.com/andreyvit/evm/kvo/codec/fast1"
)

func main() {
	original := fast1.EmptyRecord(nil)
	root := fast1.UpdateRecord(original)
	root.Set(7, 42)
	updated := root.Record().PackedRecord()
	fmt.Println(original.Root().Get(7), updated.Root().Get(7))
}
Output:
0 42

func (MutableMap) Dump

func (m MutableMap) Dump() string

Dump formats current map values for inspection.

func (MutableMap) Get

func (m MutableMap) Get(key uint64) uint64

Get reads the current word at key.

func (MutableMap) GetAnyMap

func (m MutableMap) GetAnyMap(key uint64) AnyFast1Map

GetAnyMap opens a child through the common read interface.

func (MutableMap) IsEmpty

func (m MutableMap) IsEmpty() bool

IsEmpty reports whether the map contains no entries.

func (MutableMap) IsMissing

func (m MutableMap) IsMissing() bool

IsMissing reports whether the handle refers to no record.

func (MutableMap) KeyCount

func (m MutableMap) KeyCount() int

KeyCount counts keys in the edited object.

func (MutableMap) KeySeq

func (m MutableMap) KeySeq() iter.Seq[uint64]

KeySeq iterates the current keys.

func (MutableMap) Keys

func (m MutableMap) Keys() []uint64

Keys returns the keys in the edited map.

func (MutableMap) LookupMap

func (m MutableMap) LookupMap(key uint64) (MutableMap, ImmutableMap)

LookupMap returns the edited child when present, otherwise its immutable view. Reading a child never creates an edit.

func (MutableMap) Packable

func (m MutableMap) Packable() Packable

Packable returns the enclosing record for serialization.

func (MutableMap) Record

func (m MutableMap) Record() *MutableRecord

Record returns the mutable record containing the map.

func (MutableMap) Set

func (m MutableMap) Set(key, value uint64)

Set writes a word at key.

func (MutableMap) Type

func (m MutableMap) Type() kvo.AnyType

Type returns the map's logical type.

func (MutableMap) UpdateMap

func (m MutableMap) UpdateMap(key uint64) MutableMap

UpdateMap opens the nested map at key for editing.

type MutableRecord

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

MutableRecord is a builder of ImmutableRecordDatas. It represents a delta of a tree of objects in a way that's fast to write and reasonably fast to read.

(E.g. we're using unsorted keys, so reading performance could be improved by maybe sorting keys before reading.)

func (*MutableRecord) IsDirty

func (rec *MutableRecord) IsDirty() bool

IsDirty reports whether the record has pending edits.

func (*MutableRecord) Original

func (rec *MutableRecord) Original() ImmutableRecord

Original returns the immutable record used as the edit base.

func (*MutableRecord) Pack

func (rec *MutableRecord) Pack() ImmutableRecordData

Pack produces an on-disk binary encoding of the updated record, merging the changes recorded in MutableRecord with the original record.

func (*MutableRecord) PackedRecord

func (rec *MutableRecord) PackedRecord() ImmutableRecord

PackedRecord packs the current edits into an immutable record.

func (*MutableRecord) PackedRoot

func (rec *MutableRecord) PackedRoot() ImmutableMap

PackedRoot packs current edits and returns the resulting read-only root.

func (*MutableRecord) Root

func (rec *MutableRecord) Root() MutableMap

Root opens the root object for mutation.

type Packable

type Packable interface {
	// Pack returns ImmutableRecordData of this record. Must return nil if
	// called on a nil struct pointer.
	Pack() ImmutableRecordData
}

Packable exposes the complete packed word sequence for a Fast1 record.

Jump to

Keyboard shortcuts

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