graph

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixSPOg byte = 0x10 // Subject-Predicate-Object-Graph (Standard Forward)
	PrefixPOSg byte = 0x11 // Predicate-Object-Subject-Graph (Reverse Lookup)
	PrefixPSOg byte = 0x12 // Predicate-Subject-Object-Graph (Graph Filtering)
	PrefixGSPO byte = 0x13 // Graph-Subject-Predicate-Object (Isolation Layer)

	PrefixSystem byte = 0xFF // Metadata (Count, Schema bounds, Leiden Communities)
)

Prefix keys for BadgerDB to route to proper index tables.

Variables

View Source
var (
	KeyFactCount = []byte{PrefixSystem, 0x01} // uint64 count of stored facts
)

Functions

func DecodeQuadKey

func DecodeQuadKey(key []byte) (s, p, o, g uint64, err error)

DecodeQuadKey reads the bytes back out of the index, correctly reversing the permutation.

func EncodeQuadKey

func EncodeQuadKey(prefix byte, s, p, o, g uint64) []byte

EncodeQuadKey produces a strictly aligned 33-byte slice for lexicographical sorting. By using Big-Endian representation, the numeric scale of uint64 perfectly aligns with the byte sequence scale inside BadgerDB SSTables, enabling optimal binary searches via LFTJ (Leapfrog Triejoin).

Types

type Quad added in v0.7.0

type Quad struct {
	S, P, O, G uint64
}

Quad is a batch-friendly tuple of the four quad components. See AddFact for the per-index layout.

type Store

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

Store provides the persistent BadgerDB backend for the Sovereign Logic Kernel.

func NewStore

func NewStore(path string, readOnly bool) (*Store, error)

NewStore initializes a high-performance BadgerDB instance optimized for Manglekit's read-heavy Datalog workloads and asynchronous agent write-behinds. Writes are asynchronous (WithSyncWrites(false)) — the right default for cache-style, re-derivable state. For session persistence that must survive a crash, use NewStoreWithOptions with syncWrites=true.

func NewStoreWithOptions added in v0.7.0

func NewStoreWithOptions(path string, readOnly, syncWrites bool) (*Store, error)

NewStoreWithOptions is NewStore with an explicit durability stance. syncWrites=true makes Badger fsync on write (WithSyncWrites(true)), the opt-in durability option for session persistence; the default (false) keeps asynchronous writes for cache-style usage.

func (*Store) AddFact

func (s *Store) AddFact(s_, p, o, g uint64) error

AddFact persists a single quad into all four index permutations atomically.

func (*Store) AddFacts added in v0.7.0

func (s *Store) AddFacts(quads []Quad) error

AddFacts persists a batch of quads using a single Badger write batch instead of one transaction per quad. The fact counter is updated once, atomically with the batch, counting only genuinely new facts (duplicate SPOg keys within or before the batch do not inflate it).

func (*Store) Close

func (s *Store) Close() error

Close gracefully terminates the Badger instance, flushing memtables.

func (*Store) NumFacts

func (s *Store) NumFacts() uint64

NumFacts returns the total number of stored facts (lock-free read).

func (*Store) RunVLogGC

func (s *Store) RunVLogGC(ctx context.Context)

RunVLogGC is the Incremental Garbage Collection loop required by LLD 4.2. Long-running agents constantly update temporal state, bloating the BadgerDB value logs. This MUST be called as a background goroutine.

func (*Store) Scan

func (s *Store) Scan(prefix byte, seekKey []byte, limit int, fn func(s, p, o, g uint64) bool) error

Scan performs a prefix scan over a specific index permutation. The callback receives the decoded (s, p, o, g) tuple for each matching key.

Jump to

Keyboard shortcuts

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