Help us shape the future of Go! Take the 2026 Go Developer Survey

inmemory

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver implements Storer using an in-memory map.

func NewDriver

func NewDriver() *Driver

NewDriver creates a new in-memory storer.

func (*Driver) Ancestry

func (s *Driver) Ancestry(ctx context.Context, hash string) ([]*merkle.Node, error)

Ancestry returns the path from a node back to its root (node first, root last). See AncestryChain for a variant that also signals when the walk stopped at a missing parent.

func (*Driver) AncestryChain added in v0.4.0

func (s *Driver) AncestryChain(ctx context.Context, hash string) (*storage.Chain, error)

AncestryChain walks the parent chain starting at hash and returns a Chain describing whether the walk reached a real root, stopped at a parent that is not present in this store, or was guarded out of a cycle.

func (*Driver) AncestryChains added in v0.4.0

func (s *Driver) AncestryChains(ctx context.Context, hashes []string) (map[string]*storage.Chain, error)

AncestryChains walks each input hash's ancestry and returns a Chain per starting hash. The in-memory driver has O(1) Get, so the batched ent fast path offers no benefit here — this is a straightforward loop over AncestryChain.

func (*Driver) Close

func (s *Driver) Close() error

Close is a no-op for the in-memory storer.

func (*Driver) Count

func (s *Driver) Count() int

Count returns the number of nodes in the in-memory store.

func (*Driver) CountSessions added in v0.4.0

func (s *Driver) CountSessions(_ context.Context, opts storage.ListOpts) (storage.SessionStats, error)

CountSessions returns aggregate counts for the slice of data matching opts. Pagination fields on opts are ignored.

All numeric aggregates apply per-node, matching the SQL aggregate the Postgres driver runs for /v1/stats. completed_count uses leaf-only classification (assistant leaf with a terminal stop_reason) — the chain-context overrides in pkg/sessions.DetermineStatus are deliberately NOT applied here, so both drivers return identical numbers for the same store contents.

TotalDurationNs is wall-clock span (MAX − MIN of CreatedAt) over the matching set, NOT a sum of per-call Usage.TotalDurationNs. Per-call duration is now persisted on nodes (PCC-514); switching this aggregate to SUM is a separate decision since it changes the visible semantic.

func (*Driver) Depth

func (s *Driver) Depth(ctx context.Context, hash string) (int, error)

Depth returns the depth of a node (0 for roots).

func (*Driver) Get

func (s *Driver) Get(_ context.Context, hash string) (*merkle.Node, error)

Get retrieves a node by its hash.

func (*Driver) GetByParent

func (s *Driver) GetByParent(_ context.Context, parentHash *string) ([]*merkle.Node, error)

GetByParent retrieves all nodes that have the provided parent. This is useful for determining where branching occurs.

func (*Driver) Has

func (s *Driver) Has(_ context.Context, hash string) (bool, error)

Has checks if a node exists by its hash.

func (*Driver) Leaves

func (s *Driver) Leaves(_ context.Context) ([]*merkle.Node, error)

Leaves returns all leaf nodes

func (*Driver) List

func (s *Driver) List(_ context.Context) ([]*merkle.Node, error)

List returns all nodes in the store.

func (*Driver) ListSessions added in v0.4.0

func (s *Driver) ListSessions(_ context.Context, opts storage.ListOpts) (*storage.Page[*merkle.Node], error)

ListSessions returns a page of leaf nodes (sessions), ordered by created_at descending then hash descending, optionally filtered by opts.

func (*Driver) LoadDag added in v0.5.0

func (s *Driver) LoadDag(ctx context.Context, hash string) (*merkle.Dag, error)

LoadDag takes a node hash and returns the branch containing that node: its ancestry up to the root and all descendants reachable from that node.

func (*Driver) Migrate

func (s *Driver) Migrate(_ context.Context) error

Migrate is a no-op for the in-memory storer.

func (*Driver) Open added in v0.5.0

func (s *Driver) Open(_ context.Context) error

Open is a no-op for the in-memory storer.

func (*Driver) Put

func (s *Driver) Put(_ context.Context, node *merkle.Node) (bool, error)

Put stores a node. Returns true if the node was newly inserted, false if it already existed (no-op due to content-addressing).

Put stores a copy of the node so that storage-managed metadata (currently CreatedAt) can be assigned without mutating the caller.

func (*Driver) Roots

func (s *Driver) Roots(ctx context.Context) ([]*merkle.Node, error)

Roots returns all root nodes

func (*Driver) UpdateUsage added in v0.5.0

func (s *Driver) UpdateUsage(_ context.Context, hash string, usage *llm.Usage) error

UpdateUsage updates only usage metadata on an existing node by hash.

Jump to

Keyboard shortcuts

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