graph

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package graph provides the public graph API for mache.

Types are defined in internal/graph and re-exported here via type aliases so that external consumers (e.g. x-ray) can use mache's in-memory graph without importing internal packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrActNotSupported = ig.ErrActNotSupported

ErrActNotSupported is returned by Graph implementations that do not support actions.

View Source
var ErrNotFound = ig.ErrNotFound

ErrNotFound is returned when a node ID does not exist in the graph.

View Source
var NewCompositeGraph = ig.NewCompositeGraph

NewCompositeGraph creates an empty composite graph for multi-mount routing.

View Source
var NewHotSwapGraph = ig.NewHotSwapGraph

NewHotSwapGraph creates a thread-safe graph wrapper that supports atomic Swap.

View Source
var NewMemoryStore = ig.NewMemoryStore

NewMemoryStore creates a new in-memory graph store.

Functions

func ExportSQLite added in v0.4.0

func ExportSQLite(store *MemoryStore, dbPath string) error

ExportSQLite writes all nodes from a MemoryStore to a SQLite database. Creates the nodes table if it doesn't exist. Existing entries are overwritten. The resulting file uses the standard mache nodes table schema.

Types

type ActionResult added in v0.5.0

type ActionResult = ig.ActionResult

ActionResult is returned when an action is performed on a graph node.

type CallExtractor

type CallExtractor = ig.CallExtractor

CallExtractor parses source code and returns qualified function call tokens.

type CompositeGraph added in v0.5.0

type CompositeGraph = ig.CompositeGraph

CompositeGraph multiplexes multiple Graph backends under path prefixes. Mount "browser" → /browser/... routes to that sub-graph.

type ContentRef

type ContentRef = ig.ContentRef

ContentRef is a recipe for lazily resolving file content from a backing store.

type ContentResolverFunc

type ContentResolverFunc = ig.ContentResolverFunc

ContentResolverFunc resolves a ContentRef into byte content.

type Graph

type Graph = ig.Graph

Graph is the interface for the FUSE layer and external consumers. Allows swapping the backend (Memory → SQLite → Mmap).

type GraphCache added in v0.6.0

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

GraphCache is a thread-safe MemoryStore with automatic SQLite write-through persistence. It provides tree manipulation helpers for building and querying hierarchical node structures.

Mutations acquire the write lock, modify the underlying MemoryStore, then call ExportSQLite to flush the entire graph to disk. On construction, ImportSQLite loads any previously persisted state.

Domain-specific logic (fingerprint matching, eviction policies, custom node layouts) is NOT part of GraphCache. Consumers build those on top using the tree manipulation primitives and the Store() escape hatch.

func NewGraphCache added in v0.6.0

func NewGraphCache(dbPath string) *GraphCache

NewGraphCache creates a GraphCache backed by SQLite at dbPath. If dbPath is empty, the cache is purely in-memory (suitable for tests). If dbPath points to an existing SQLite file, the previously persisted graph is loaded via ImportSQLite.

func (*GraphCache) AppendChild added in v0.6.0

func (c *GraphCache) AppendChild(parentID, childID string) bool

AppendChild adds childID to the Children list of parentID if not already present. Returns false if the parent does not exist.

func (*GraphCache) Batch added in v0.6.0

func (c *GraphCache) Batch(fn func(*MemoryStore)) error

Batch acquires the write lock, calls fn with the underlying MemoryStore, then persists once. Use this for multi-step mutations that must be atomic (no concurrent readers see intermediate state) and persist as a single SQLite write instead of N individual writes.

This is the correct way to implement complex operations like "backup sections, clear zones, rebuild zones, restore matching sections" — the entire sequence runs under one lock with one persist at the end.

func (*GraphCache) ClearChildren added in v0.6.0

func (c *GraphCache) ClearChildren(id string) bool

ClearChildren sets the Children list of a directory node to empty. Returns false if the node does not exist. Combined with RemoveChild on the parent, this effectively "deletes" a subtree: ExportSQLite only walks from roots, so orphaned nodes are not persisted.

func (*GraphCache) Close added in v0.6.0

func (c *GraphCache) Close() error

Close is a no-op. ExportSQLite manages its own DB connections per call.

func (*GraphCache) GetData added in v0.6.0

func (c *GraphCache) GetData(id string) ([]byte, bool)

GetData returns the Data field of a file node, or (nil, false) if the node does not exist or has no data.

func (*GraphCache) GetNode added in v0.6.0

func (c *GraphCache) GetNode(id string) (*Node, bool)

GetNode returns the node at the given id, or (nil, false) if not found.

func (*GraphCache) ListChildren added in v0.6.0

func (c *GraphCache) ListChildren(id string) ([]string, bool)

ListChildren returns the Children of a directory node, or (nil, false) if the node does not exist or is not a directory.

func (*GraphCache) Persist added in v0.6.0

func (c *GraphCache) Persist() error

Persist flushes the entire graph to SQLite. Called automatically by mutation methods. Use explicitly after direct Store() access.

func (*GraphCache) PutDir added in v0.6.0

func (c *GraphCache) PutDir(id string, isRoot bool) bool

PutDir ensures a directory node exists at the given id. If isRoot is true and the node is new, it is registered as a root node. Returns true if a new node was created.

func (*GraphCache) PutFile added in v0.6.0

func (c *GraphCache) PutFile(id string, data []byte)

PutFile creates or overwrites a file node with the given data. The node's ModTime is set to time.Now().

func (*GraphCache) RemoveChild added in v0.6.0

func (c *GraphCache) RemoveChild(parentID, childID string) bool

RemoveChild removes childID from the Children list of parentID. Returns false if the parent does not exist.

func (*GraphCache) RootIDs added in v0.6.0

func (c *GraphCache) RootIDs() []string

RootIDs returns all root node IDs.

func (*GraphCache) Store added in v0.6.0

func (c *GraphCache) Store() *MemoryStore

Store returns the underlying MemoryStore for direct access. Use this for batch operations: mutate the store directly, then call Persist() once. Callers are responsible for coordinating with GraphCache.mu if mixing direct store access with GraphCache mutation methods.

type HotSwapGraph added in v0.5.2

type HotSwapGraph = ig.HotSwapGraph

HotSwapGraph is a thread-safe wrapper that allows atomically swapping the underlying graph. Readers hold an RLock during each call; Swap acquires a write lock. Use this instead of hand-rolled mutex+pointer patterns.

type MemoryStore

type MemoryStore = ig.MemoryStore

MemoryStore is an in-memory implementation of Graph with roaring bitmap indexing.

func ImportSQLite added in v0.4.0

func ImportSQLite(dbPath string) (*MemoryStore, error)

ImportSQLite reads nodes from a SQLite database into a new MemoryStore. The database must have a nodes table in the standard mache format.

type Node

type Node = ig.Node

Node is the universal primitive for files and directories. The Mode field declares whether this is a file or directory.

type QualifiedCall

type QualifiedCall = ig.QualifiedCall

QualifiedCall represents a function call with optional package qualifier.

type SourceOrigin

type SourceOrigin = ig.SourceOrigin

SourceOrigin tracks the byte range of a construct in its source file.

Jump to

Keyboard shortcuts

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