Skip to content

Replace DJB2 with FNV-1a hash and enhance CRDT merge#44

Open
ib823 wants to merge 1 commit intomainfrom
claude/content-addressed-codegen-H3nGF
Open

Replace DJB2 with FNV-1a hash and enhance CRDT merge#44
ib823 wants to merge 1 commit intomainfrom
claude/content-addressed-codegen-H3nGF

Conversation

@ib823
Copy link
Owner

@ib823 ib823 commented Mar 19, 2026

Summary

Refactor hashing and CRDT merge operations to use industry-standard FNV-1a algorithm instead of DJB2, add support for hashing and merging composite types (Pairs, Strings), and make content hashing idempotent.

Changes

  • Hash algorithm: Replace DJB2 with FNV-1a (offset basis: 14695981039346656037, prime: 1099511628211) in both Rust interpreter and C emitter
  • Composite type support: Extend fnv1a_feed() to handle Pair and Hash values with tag bytes (0x01, 0x02) for disambiguation
  • Idempotent hashing: Add Value::is_hash() check so hash(hash(x)) == hash(x) for all values
  • Enhanced CRDT merge: Implement recursive merge for Pair types and add lexicographic max for String values (LWW-Register semantics)
  • Code organization: Extract hash and merge logic into standalone functions (fnv1a_hash_value(), crdt_merge_values()) for reusability
  • C codegen: Update emitted C code to use FNV-1a constants and XOR-multiply operations

Type

  • Refactor
  • New feature (composite type hashing, idempotent hashing, enhanced CRDT merge)

Testing

  • Added 11 new unit tests covering:
    • Content hash of pairs with deterministic output
    • Hash idempotency (single, double, triple application)
    • CRDT merge for strings (commutativity, lexicographic max)
    • CRDT merge for pairs (componentwise merge, commutativity, associativity)
    • C codegen verification (FNV constants, CRDT merge function presence)
  • All tests verify correctness of new hash algorithm and merge semantics

Checklist

  • No external dependencies added
  • No unsafe without justification
  • New tests added for new functionality

https://claude.ai/code/session_0152RhmcLYA5zwBLumJ9U1Nr

…5 tests)

- Replace DJB2 with FNV-1a (offset=14695981039346656037, prime=1099511628211)
  in both interpreter (interp.rs) and C backend (emit.rs)
- Add pair/tuple hashing support with tag byte separation
- Make nested ContentHash idempotent (hash of hash = same hash)
- Extend CRDTMerge: strings (lexicographic max), pairs (componentwise)
- Extract fnv1a_feed/fnv1a_hash_value and crdt_merge_values helper functions
- Add 15 new tests: pair hashing, idempotency, string merge, pair merge,
  associativity, commutativity, FNV constants in C output, crdt_merge in C

https://claude.ai/code/session_0152RhmcLYA5zwBLumJ9U1Nr
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