Skip to content

Rewrite as a minimal Bun/TypeScript library with map, set, list and Gk-trees - #6

Merged
carsonfarmer merged 4 commits into
mainfrom
claude/practical-goldberg-z4v0o2
Sep 22, 2026
Merged

carsonfarmer merged 4 commits into
mainfrom
claude/practical-goldberg-z4v0o2

Conversation

@carsonfarmer

Copy link
Copy Markdown
Owner

Summary

Replaces the Deno sources with a small Bun/TypeScript library (about 680 lines in src/) that follows the paper's unzip/zip formulation and exposes usable map, set and list types.

  • Core (src/tree.ts): one G-tree implementation over a pluggable inner set. Items has six members and allows empty sets, so no Set<S> wrapper is needed. Insert is zip(zip(before, single), after), delete is zip(before, after); map set is therefore an upsert for free.
  • Facades: GMap, GSet (JS-native get/set/has/delete/add/size, iteration in key order) and GList (positional at/insert/remove/slice/concat/splitAt, sharing zip).
  • Ranks (src/rank.ts): hashed by default, so trees are history independent and structurally equal for equal sets; random(k) for keys with no hash. k = 2 gives a zip tree, the default k = 8 was picked by the benchmark.
  • Gk-trees (src/gk.ts), after Hehemann's thesis section 4.1: TreeItems stores a node's entries as a G-tree with a reseeded rank (zip-zip trees on their own), and GkItems is an array that converts to a TreeItems past a threshold and back below it. Converting both ways at one size keeps history independence. Node Items carry a weight so rebuilding a tree-mode node stays O(1) rather than O(entries).
  • Tests (bun test, 24 tests, invariant checker with a seeded PRNG), benchmark, typecheck, build with declarations, CI workflow, rewritten README.

Notes

  • The separate BinaryZipTree/ZipSequence classes are gone; a zip tree is now { k: 2 }, represented as the paper's runs-of-equal-rank form rather than left/right binary nodes.
  • The default hash uses Bun.hash; other runtimes need a custom rank.
  • Default Gk threshold is 12k: a single threshold with hysteresis would be history dependent, and at 12k honest nodes essentially never convert, while a node pinned at the threshold by an adversary costs a bounded constant.

Test plan

  • bun run typecheck
  • bun test
  • bun run build
  • bun run bench (k=8 fastest for insert/get; Gk variant within noise of plain on honest data)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NTbgsritf5j3MP1V7UsU3p


Generated by Claude Code

Replace the Deno sources with a small core (src/tree.ts) that follows the
paper's unzip/zip formulation over a pluggable inner set, plus GMap, GSet
and GList facades with JS-native APIs. Ranks are hashed by default so trees
are history independent; random ranks remain available.

Add Gk-trees (src/gk.ts) after Hehemann's thesis, section 4.1: node items
become a G-tree of their own past a threshold, which bounds node sizes
under adversarial keys. This drops in as another Items implementation.

Tests run under bun test; a benchmark script picks k=8 as the default.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTbgsritf5j3MP1V7UsU3p
Replace Bun.hash with cyrb53 so the default rank works on any runtime;
drop the bun export condition and add a Node smoke test of the built
package to CI. Remove sideEffects: false, which made the bundler drop the
re-exported facade modules.

Add src/binary.ts, the classic binary zip tree with the same function
names as the G-tree core, and tests that reproduce the paper's figure and
unfold a k = 2 G-tree into the binary tree to check they coincide.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTbgsritf5j3MP1V7UsU3p
Replace the trailing-zero division loop with one logarithm plus an exact
integer check against precomputed powers of k, so ranks cost the same for
any k and are bit-identical across runtimes. Add tests against a BigInt
reference at every boundary and for the geometric tail.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTbgsritf5j3MP1V7UsU3p
Make the Hash contract a 32-bit integer, the convention of xxHash32,
MurmurHash3 and similar, and normalise signed results, so external hashes
drop in without scaling. Fold the built-in hash to 32 bits to match.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTbgsritf5j3MP1V7UsU3p
@carsonfarmer carsonfarmer mentioned this pull request Sep 22, 2026
3 tasks done
@carsonfarmer
carsonfarmer merged commit 107c99e into main Sep 22, 2026
1 check passed
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.

2 participants