# igotlinux/pbtree architecture

> Architecture diagram of the GitHub repository igotlinux/pbtree, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/igotlinux/pbtree
- Repository: https://github.com/igotlinux/pbtree

## Overview

This C++ library provides a persistent copy-on-write B+ tree: writes create a new version while preserving earlier snapshots, and reads can target either the current tree or a historical snapshot. Its internal node layer implements intrusive reference counting and cascading reclamation. The repository also includes a linked-delta baseline for comparing versioned lookup and storage costs. Relationships for the benchmark are based on README documentation; its source was not sampled.

Main entry points: [`include/pbtree/btree.hpp`](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp) (Tree API), [`include/pbtree/node.hpp`](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp) (Intrusive NodePtr), [`bench/benchmark.cpp`](https://github.com/igotlinux/pbtree/blob/main/bench/benchmark.cpp) (Performance Benchmark), [`include/pbtree/delta_chain.hpp`](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/delta_chain.hpp) (Delta Chain Store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tree["Persistent B+ Tree"]
  node_tree_api["Tree API<br/>[btree.hpp]"]
  node_path_copy["Path Copying<br/>[btree.hpp]"]
  node_snapshot["Snapshots<br/>[btree.hpp]"]
  node_point_lookup["Point Lookup<br/>[btree.hpp]"]
  node_range_scan["Range Scan<br/>[btree.hpp]"]
end

subgraph group_memory["Node Memory"]
  node_tree_nodes["Tree Nodes<br/>[node.hpp]"]
  node_node_ptr["Intrusive NodePtr<br/>[node.hpp]"]
  node_reclamation["Node Reclamation<br/>[node.hpp]"]
end

subgraph group_comparison["Benchmark Comparison"]
  node_benchmark["Performance Benchmark<br/>[benchmark.cpp]"]
  node_delta_store["Delta Chain Store<br/>[delta_chain.hpp]"]
end

node_client(("Library Caller"))

node_client -->|"calls"| node_tree_api
node_tree_api -->|"dispatches writes"| node_path_copy
node_tree_api -->|"creates snapshots"| node_snapshot
node_tree_api -->|"routes lookups"| node_point_lookup
node_tree_api -->|"routes scans"| node_range_scan
node_path_copy -->|"copies path nodes"| node_tree_nodes
node_path_copy -->|"shares subtrees"| node_node_ptr
node_snapshot -->|"copies root handle"| node_node_ptr
node_point_lookup -->|"traverses nodes"| node_tree_nodes
node_range_scan -->|"traverses nodes"| node_tree_nodes
node_node_ptr -->|"releases references"| node_reclamation
node_benchmark -.->|"measures"| node_tree_api
node_benchmark -.->|"compares against"| node_delta_store

click node_tree_api "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp"
click node_path_copy "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp"
click node_snapshot "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp"
click node_point_lookup "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp"
click node_range_scan "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp"
click node_tree_nodes "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp"
click node_node_ptr "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp"
click node_reclamation "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp"
click node_benchmark "https://github.com/igotlinux/pbtree/blob/main/bench/benchmark.cpp"
click node_delta_store "https://github.com/igotlinux/pbtree/blob/main/include/pbtree/delta_chain.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tree_api,node_path_copy,node_snapshot,node_point_lookup,node_range_scan toneBlue
class node_tree_nodes,node_node_ptr,node_reclamation toneAmber
class node_benchmark,node_delta_store toneMint
class node_client toneIndigo
```

## Components

### Persistent B+ Tree

- [Tree API](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp): `include/pbtree/btree.hpp`
- [Path Copying](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp): `include/pbtree/btree.hpp`
- [Snapshots](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp): `include/pbtree/btree.hpp`
- [Point Lookup](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp): `include/pbtree/btree.hpp`
- [Range Scan](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/btree.hpp): `include/pbtree/btree.hpp`

### Node Memory

- [Tree Nodes](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp): `include/pbtree/node.hpp`
- [Intrusive NodePtr](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp): `include/pbtree/node.hpp`
- [Node Reclamation](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/node.hpp): `include/pbtree/node.hpp`

### Benchmark Comparison

- [Performance Benchmark](https://github.com/igotlinux/pbtree/blob/main/bench/benchmark.cpp): `bench/benchmark.cpp`
- [Delta Chain Store](https://github.com/igotlinux/pbtree/blob/main/include/pbtree/delta_chain.hpp): `include/pbtree/delta_chain.hpp`

### Other components

- **Library Caller**

## Connections

- Library Caller → Tree API: calls (evidence: `README.md`)
- Tree API → Path Copying: dispatches writes (evidence: `include/pbtree/btree.hpp`)
- Tree API → Snapshots: creates snapshots (evidence: `include/pbtree/btree.hpp`)
- Tree API → Point Lookup: routes lookups (evidence: `include/pbtree/btree.hpp`)
- Tree API → Range Scan: routes scans (evidence: `include/pbtree/btree.hpp`)
- Path Copying → Tree Nodes: copies path nodes (evidence: `include/pbtree/btree.hpp`)
- Path Copying → Intrusive NodePtr: shares subtrees (evidence: `include/pbtree/btree.hpp`)
- Snapshots → Intrusive NodePtr: copies root handle (evidence: `include/pbtree/btree.hpp`)
- Point Lookup → Tree Nodes: traverses nodes (evidence: `include/pbtree/btree.hpp`)
- Range Scan → Tree Nodes: traverses nodes (evidence: `include/pbtree/btree.hpp`)
- Intrusive NodePtr → Node Reclamation: releases references (evidence: `include/pbtree/node.hpp`)
- Performance Benchmark → Tree API: measures (evidence: `README.md`)
- Performance Benchmark → Delta Chain Store: compares against (evidence: `README.md`)
