Skip to content

Refactor graph ids toward append-only allocation#45

Draft
rollrat wants to merge 10 commits into
masterfrom
codex/nbt-sim-optimization-options
Draft

Refactor graph ids toward append-only allocation#45
rollrat wants to merge 10 commits into
masterfrom
codex/nbt-sim-optimization-options

Conversation

@rollrat
Copy link
Copy Markdown
Member

@rollrat rollrat commented May 31, 2026

Summary

  • make petgraph conversion sparse-node-id safe
  • preserve graph node ids through world-to-logic transforms instead of compacting them
  • remove rebuild_node_ids paths and map QMC terms through dense input ids internally
  • add tests for sparse ids, append-only id allocation, and unsorted node lookup/removal

Testing

  • cargo test --release

rollrat added 10 commits May 31, 2026 11:41
Keep graph node identifiers stable across world-to-logic transforms by removing compact id rebuilds and making petgraph conversion sparse-id safe. This prepares the graph model for provenance metadata without relying on node vector ordering.
Introduce a graph-owned node id counter and add coverage that newly allocated ids do not reuse removed node ids. This is the first step toward moving node identity out of GraphNode payloads.
Move Graph.nodes behind an id-keyed container so node ordering is structural instead of maintained by ad hoc sorts or binary-search insertion. This keeps synthetic ids append-only across removals during world-to-logic transforms and removes the transform-level manual sort.
Add Graph::from_nodes so imported graphs initialize next_node_id from existing node ids instead of patching allocator state during deletion. Update graph construction sites to use that API and remove the preserve_next_node_id_high_watermark deletion hook.
Collapse overlapping sparse-id, id-keyed storage, and append-only allocator tests into one focused graph regression while keeping the world-to-logic sparse synthetic-node test. This reduces test fixture bulk without dropping the core invariants.
Switch the graph node storage wrapper from BTreeMap to IndexMap while preserving deterministic id-ordered iteration at construction and insertion. This keeps the storage ready for graph-owned node ids without changing traversal output.
Make Graph own node id storage by moving ids out of GraphNode and into GraphNodes entries. Preserve sparse and append-only ids through explicit keyed construction while keeping existing graph transforms and placer code on node references that carry storage ids.
Fix comments that were mojibaked during the GraphNode id refactor. This keeps the code behavior unchanged and restores the original Korean explanatory comments around graph merge and rebuild helpers.
Keep GraphNodeId production behind Graph::add_node and keyed graph construction. Remove direct keyed insertion and local synthetic id counters from graph builders, transforms, and clustered graph construction so transforms no longer mint graph ids outside Graph.
Move graph merging to allocator-backed imports so imported nodes receive fresh ids and internal edges are remapped through explicit old-to-new mappings. This keeps GraphNodeId production inside GraphNodes and removes rebuild-style id shifting from graph merges and logic binop replacement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant