Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Project: audit capacity, medians, and scan integrity

Last updated: 5 Oct 202625 min read
project
IntermediateBy AITrove Editorial

A depot console accepts capacity corrections across days, appends scan counts, and seals a batch of raw scan records. Use three independent checks. An ordinary list receives every range correction and supplies sums by slicing. A sorted copy of all recorded counts supplies the exact median after each append. A freshly built hash tree checks that a proof belongs to a separately retained root and batch size. These checks should run after mixed operations, including empty ranges, negative corrections, duplicate counts, and an odd batch length. The structures solve different problems: arithmetic changes to a fixed array, order statistics over an append-only stream, and evidence that a byte record occupied one position in one committed batch. Sharing a dashboard does not make their update rules interchangeable.

Acceptance trace

Initialize capacities 23, 47, 19, 61, 38. Add seven over [1, 4), subtract four over [3, 5), and require 178 for [1, 5). Record scan counts 47, 19, 61, 26, 83, then 52: the two medians are 47 and 99/2. Seal five byte records with D-61:19 at index three. The original record verifies against the stored root; D-61:20 must fail against the same root. Replacing a capacity value is not the same as adding a difference. Editing a sealed record changes its leaf digest and requires a new root.

Expected output

Output
range-sum=178 median-five=47 median-six=99/2
original-proof=true altered-proof=false

Boundary and cost review

Validate each half-open range before changing either Fenwick tree. Check the heap-size and ordering invariants after each count; an empty stream has no median. Reject a proof with missing or extra siblings, a wrong position, or a wrong batch size. The batch root and size need an authenticated source. A rebuilt hash tree is not an append-consistency protocol, and the example's median heaps do not evict expired readings. State whether reports use raw integer counts or another numeric unit before computing an exact fraction.

Common Mistakes

  • Do not mistake a range addition for assignment.
  • Do not average heap tops after an odd number of records.
  • Do not accept a proof against a root supplied by the same untrusted party.
  • Do not leave the batch size out of an odd-node proof check.

Connected lessons

data structures
projects
Storage details