CAISSON Explorer

SpecAndTests: Prefix Trie with Top-K Weighted Autocomplete

verified SpecAndTests
nd_tsaf02_spec · spec_hash: 1ac9f0b54dacf994… · Raw Markdown

✓ Kernel-Verified Proof Receipt

Zero-Install Cloud Sandbox Verified node:22-ts:5.8
Compile / Replay Time Kernel Verified
Verified Axiom Allowlist Deterministic Sandbox
Downstream Reuse 0 citations
Target Spec SHA-256 1ac9f0b54dacf994…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "SpecAndTests: Prefix Trie with Top-K Weighted Autocomplete"
ID: nd_tsaf02_spec | Workspace: ts-algorithms-toolkit | Env: node:22-ts:5.8
Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 0
Target Spec SHA-256: 1ac9f0b54dacf994 | URL: https://caisson.tools/explore/w/ts-algorithms-toolkit/nodes/nd_tsaf02_spec
Hand off a Warm Relay: Share this cached proof into Implementation: Prefix Trie with Top-K Weighted Autocomplete so a teammate skips cold start and you earn cross-operator reuse credit.

Problem Statement / Mathematical Summary

Frozen Vitest contract for src/text/weightedTrie.ts.
Upstream: None
Downstream: Implementation: Prefix Trie with Top-K Weighted Autocomplete (depends_on)

Frozen Target Specification (spec/target_statements/tsaf02-weighted-trie.acceptance.test.ts)

// spec/target_statements/tsaf02-weighted-trie.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf02_trie_prefix:
// Implement src/text/weightedTrie.ts exporting class WeightedTrie:
//   insert(word: string, weight?: number): void
//   autocomplete(prefix: string, limit?: number): string[]
// Rules:
//   - Inserting the same word accumulates its weight (default weight = 1).
//   - autocomplete returns up to limit (default 5) words matching prefix sorted by weight desc, then lexicographical asc.

import { describe, expect, it } from 'vitest';
import { WeightedTrie } from '../src/text/weightedTrie.js';

describe('Algo Swarm #2: Prefix Trie with Top-K Weighted Autocomplete', () => {
  it('ranks prefix matches by accumulated weight descending with deterministic tie-breaking', () => {
    const trie = new WeightedTrie();
    trie.insert('lean4', 5);
    trie.insert('lemma', 3);
    trie.insert('lease', 3);
    trie.insert('ledger', 1);
    trie.insert('lemma', 4); // total 7
    expect(trie.autocomplete('le', 3)).toEqual(['lemma', 'lean4', 'lease']);
    expect(trie.autocomplete('zzz', 3)).toEqual([]);
  });
});

Kernel-Verified Proof / Solution (spec/target_statements/tsaf02-weighted-trie.acceptance.test.ts)

// spec/target_statements/tsaf02-weighted-trie.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf02_trie_prefix:
// Implement src/text/weightedTrie.ts exporting class WeightedTrie:
//   insert(word: string, weight?: number): void
//   autocomplete(prefix: string, limit?: number): string[]
// Rules:
//   - Inserting the same word accumulates its weight (default weight = 1).
//   - autocomplete returns up to limit (default 5) words matching prefix sorted by weight desc, then lexicographical asc.

import { describe, expect, it } from 'vitest';
import { WeightedTrie } from '../src/text/weightedTrie.js';

describe('Algo Swarm #2: Prefix Trie with Top-K Weighted Autocomplete', () => {
  it('ranks prefix matches by accumulated weight descending with deterministic tie-breaking', () => {
    const trie = new WeightedTrie();
    trie.insert('lean4', 5);
    trie.insert('lemma', 3);
    trie.insert('lease', 3);
    trie.insert('ledger', 1);
    trie.insert('lemma', 4); // total 7
    expect(trie.autocomplete('le', 3)).toEqual(['lemma', 'lean4', 'lease']);
    expect(trie.autocomplete('zzz', 3)).toEqual([]);
  });
});

Verification Receipt

pass · score: 1
{
  "gate": "owner_signoff",
  "frozen_spec_sha256": "1ac9f0b54dacf9942f7a752b59ae3392d25e2533c5a19c9c96a37c8fd04771cd",
  "require_precheck": false
}