A Proximity Order Trie (POT) for Swarm,
written in Zig — a mutable, content-addressable key/value index that
(once Phase 2 lands) persists on Swarm. A Zig take on
ethersphere/proximity-order-trie,
sibling to the Rust/Go/Py/TS clients under
ethswarm-tools.
A POT organizes entries by the proximity order of their keys — the position of the first bit that differs from a node's pivot key — so lookups branch on PO instead of one bit/byte at a time, and depth is bounded by key-bit length.
- Phase 1 — in-memory core: done.
proximityOrder+ a mutableIndexwithput/get/contains/delete/iterate/count. - Phase 2 — Swarm persistence: done. BMT/keccak256 chunk addressing
(vector-checked against bee-rs/bee-go, so a Bee node accepts the
chunks), one-chunk-per-node serialization, and
Index.save/loadthrough a pluggableStore.MemStore(in-memory, content-addressed, deduping) andBeeStore(POST/GET /chunkswith the postage-batch header) ship today. The root chunk address is the database handle. (Verified live against a Bee node — Sepolia testnet, Bee 2.7.2: keys uploaded with a postage stamp viaPOST /chunksand read back viaGET /chunks.) - Phase 3 — CLI: done.
put/get/del/listover a local--dirstore or a--beenode; the printed root chunk address is the database handle you thread back with--root.demoruns in-memory.
26 tests, leak-checked, zig fmt clean (zig build test). Built for
Zig 0.16. Canonical save (same key/value set → same root) and a
walkStructure introspection API (used by zigpot-tui) are included.
zig build # builds ./zig-out/bin/zigpot
zigpot put name ada --dir ./db # → prints root1
zigpot put lang zig --root <root1> --dir ./db # → prints root2
zigpot get name --root <root2> --dir ./db # → ada
zigpot list --root <root2> --dir ./db
zigpot del lang --root <root2> --dir ./db # → root back to {name}Swap --dir <path> for --bee <url> [--stamp <batch>] (or $BEE_BATCH_ID)
to persist on Swarm instead of local disk. Mutations are content-addressed,
so the same logical contents always produce the same root.
zig build test # run the unit tests
zig build run # run the demoRequires Zig 0.15.x.
const zigpot = @import("zigpot");
var idx = zigpot.Index.init(allocator, 256); // 256 = max proximity order
defer idx.deinit();
try idx.put("hello", "world");
const v = idx.get("hello"); // ?[]const u8
_ = try idx.delete("hello"); // boolMIT (see LICENSE-MIT). Dual MIT OR Apache-2.0 to match the sibling
crates will be finalized before any release.