Persistent storage and retrieval of ternary knowledge with conservation-law verification.
ternary-archive provides an append-only knowledge store where each record (a "scroll") is an immutable ternary-valued entry drawn from balanced ternary
In a balanced ternary system, knowledge has value — and value must be conserved. Every record written to the archive carries a ternary charge:
This crate enforces that invariant through a Conservation tracker with
Each scroll is an immutable record with a monotonically increasing ID:
where
The archive maintains three inverted indexes as hash maps:
| Index | Key | Value | Lookup |
|---|---|---|---|
by_category |
String |
Vec<u64> |
|
by_key |
String |
Vec<u64> |
|
by_value |
Ternary |
Vec<u64> |
|
Insertion appends to each index in HashMap<u64, Scroll>.
The Conservation tracker maintains a running sum and count:
where
The would_violate check tests whether adding a new value would push
This is an
The ArchiveCurator manages a four-stage lifecycle with enforced ordering:
Active ──deprecate()──▶ Deprecated ──archive()──▶ Archived ──expire()──▶ Expired
Transitions skip-proof: each stage can only transition to the next. Attempts to skip stages (e.g., Active → Archived) return false without modifying state.
Complexity: All lifecycle operations are count_by_stage operation is
The Catalog provides a hierarchical view grouped by category, storing full Scroll objects (not just IDs). This enables efficient category-level browsing in
[dependencies]
ternary-archive = "0.1"use ternary_archive::{Archive, Ternary, ArchiveCurator, LifecycleStage};
let mut archive = Archive::new();
// Store knowledge
let id1 = archive.store("physics", "momentum", Ternary::Pos, 100);
let id2 = archive.store("physics", "drag", Ternary::Neg, 101);
let id3 = archive.store("meta", "version", Ternary::Zero, 102);
// Conservation check: +1 + (-1) + 0 = 0 → balanced
assert!(archive.is_balanced());
assert_eq!(archive.conservation_balance(), 0);
// Multi-index retrieval
assert_eq!(archive.find_by_category("physics").len(), 2);
assert_eq!(archive.find_by_value(Ternary::Pos).len(), 1);
// Lifecycle management
let mut curator = ArchiveCurator::new();
curator.register(id1);
curator.deprecate(id1, "superseded by relativity");
assert_eq!(curator.stage(id1), Some(LifecycleStage::Deprecated));| Type | Purpose | Key Methods |
|---|---|---|
Ternary |
The {-1, 0, +1} value type | from_i8(), to_i8() |
Scroll |
Immutable archive record | id(), category(), key(), value(), with_metadata() |
Index |
Three-way inverted index | lookup_category(), lookup_key(), lookup_value() |
Catalog |
Category-grouped browsing | add(), browse(), categories() |
Conservation |
O(1) conservation tracker | record(), balance(), is_balanced(), deviation(), would_violate() |
Archive |
Main knowledge store | store(), retrieve(), find_by_*(), is_balanced() |
ArchiveCurator |
Lifecycle management | register(), deprecate(), archive(), expire() |
LifecycleStage |
Active / Deprecated / Archived / Expired | — |
The archive enforces the SuperInstance conservation law γ + η = C. Each ternary value contributes to the system's total charge:
The Conservation tracker directly computes this sum in
The lifecycle stages map to energy states: Active scrolls have high
- Cover, T.M. & Thomas, J.A. Elements of Information Theory. 2nd ed., Wiley, 2006. — Shannon entropy and information conservation.
- Knuth, D.E. The Art of Computer Programming, Vol. 3: Sorting and Searching. §6.5, on multi-key retrieval structures.
- Lamport, L. The Part-Time Parliament. ACM TOCS 1998. — Consensus and immutability in distributed logs.
- Bernstein, P.A. & Newcomer, E. Principles of Transaction Processing. Ch. 7, on append-only storage and lifecycle management.
MIT