Complete native adjacent deduplication and multiplicity arrays #
The input is a sorted array. The program counts one maximal adjacent run, emits its key and full count, and repeats. The output consists of two adjacent arrays, each with capacity equal to the input length. All run tests, loads, stores, address calculations and control instructions are charged. The total time is linear, including repeated keys and empty inputs.
Main definitions #
flush: store one key/count pair and advance the output cursor.body: count and emit one complete run.code: the full adjacent deduplication program.
Main results #
exec: full unique-key and multiplicity output with a linear native instruction bound.
Store one key/count pair and advance the output cursor.
Instances For
Count and emit the next maximal run.
Instances For
Initialize the two cursors and count all adjacent runs.
Instances For
Emit each distinct key once and its full multiplicity in at most 29n+5 instructions.
The input precedes the two output blocks; no input cells or cells outside the output blocks
change. Counts are ordinary unsigned words bounded by n. No restriction on key signs or
canonical encodings is needed: in particular canonical Signed.encode inputs are admitted.