hspZ v0.0.4

G. Deterministic output

Compact, deduplicate, order, convert, partition, and emit the exact segment records LASTZ consumes.

Output is a semantic stage: dedup scope, previous-input comparisons, strand traversal, coordinate conversion, and ordinal replay all affect final bytes.

reference  ref_start  ref_end  query  query_start  query_end  strand  score
chr20      10541      10608    chr19  7731         7798       +       4187

coordinates: chromosome-relative · 1-based · inclusive
G.1 — Compact accepted HSPsStep 1 of 5

WHAT GOES IN: Materialized SegmentPairs and their inclusive-scan done flags. WHAT HAPPENS: The device copies accepted records into increasing materializer order and the host receives only the active prefix. WHAT COMES OUT: A dense vector of raw accepted HSPs for one MAX_HITS chunk. INVARIANT: Compaction changes storage density, never the relative order of accepted records.

Readable journey

Step 1

G.1 — Compact accepted HSPs

what goes in
Materialized SegmentPairs and their inclusive-scan done flags.
what happens
The device copies accepted records into increasing materializer order and the host receives only the active prefix.
what comes out
A dense vector of raw accepted HSPs for one MAX_HITS chunk.
invariant
Compaction changes storage density, never the relative order of accepted records.
  1. Materialized HSPs → Stable compactor: candidate records
  2. Done scan → Stable compactor: inclusive accepted ranks
  3. Stable compactor → Raw accepted HSPs: accepted records in order
Step 2

G.2 — Reproduce oracle deduplication

what goes in
Raw accepted HSPs from one chunk and strand.
what happens
A stable diagonal sort makes equivalent runs adjacent; unique-copy compares each record with the previous input record.
what comes out
One survivor for each oracle equivalence run.
invariant
Comparing with the last kept record instead would be wrong because containment is not transitive.
  1. Raw HSPs → Diagonal stable sort: diagonal, ref start, len, score
  2. Diagonal stable sort → Previous-input dedup: adjacent contained runs
  3. Previous-input dedup → Kept HSPs: first item of each run
Step 3

G.3 — Put survivors in LASTZ order

what goes in
Deduplicated SegmentPairs.
what happens
A second stable sort orders query start, reference start, length, then descending score.
what comes out
LASTZ query-major segment order.
invariant
Sort stability and unsigned wrapping diagonal semantics are part of byte parity.
  1. Kept HSPs → LASTZ stable sort: query/ref/len/score keys
  2. LASTZ stable sort → Ordered segments: query-major order
Step 4

G.4 — Convert to chromosome coordinates

what goes in
Block-relative SegmentPairs, chromosome tables, and strand.
what happens
Upper-bound lookup finds each chromosome; starts become one-based and ends remain inclusive. Minus records are traversed in reverse.
what comes out
Eight numeric/text fields for each `.segments` line.
invariant
Coordinate conversion never stitches across the `&` separator between chromosomes.
  1. Ordered HSPs → Record converter: block-relative start + extent
  2. Record converter → Chr tables: upper-bound chromosome lookup
  3. Chr tables → Record converter: name + block offset
  4. Record converter → Segment text: 1-based inclusive fields
Step 5

G.5 — Emit deterministic files or one archive

what goes in
Completed WorkUnits arriving in any GPU completion order.
what happens
Ordinals are replayed; optional diagonal partitioning runs before a directory or reproducible tar sink writes non-empty entries. With `--query-list`, every job has its own ordinal cursor, `-D` history and sink.
what comes out
`tmp<n>.block<q>.r<r>.{plus,minus}[.splitN].segments` files.
invariant
Worker completion order never changes filenames, partition history, archive entry order, or bytes.
  1. Completed WorkUnits → Ordinal buffer: out-of-order results
  2. Ordinal buffer → Optional partitioner: next ordinal only
  3. Optional partitioner → Output sink: whole or split records
  4. Output sink → Output sink: directory or reproducible tar