PATCHED
PATCHED stores most values as a Packed array and fixes up a few outliers from an exception list. It is codec id 5 in Flat and in IntCol, with the same layout in both.
Layout
Section titled “Layout”| Field | Encoding | Meaning |
|---|---|---|
| count | varint | n, the number of values |
| codec | u8 | 5 |
| base | Packed(n) |
the base values, one slot per value |
| e | varint | number of exceptions |
| positions | Packed(e) |
exception positions, ascending |
| values | Packed(e) |
exception values, in the same order as the positions |
How to decode
Section titled “How to decode”- Read
count, the codec byte (5) and the basePacked(n). - Read
e, then the positionsPacked(e)and the exception valuesPacked(e). - For each slot
i, if its base value equalsbase.min, lookiup in the positions. When it is listed, the value is the matching exception value. Otherwise the value is the base value. - A slot whose base value is above
base.minis never an exception.
Slots that are exceptions hold base.min in the base array, which is why only min-valued slots need to be looked up.
Illustration
Section titled “Illustration”Derived by hand, not from a real file. The values are 0, 1, 2, 3, 1000. The writer stores the base as 0, 1, 2, 3, 0 (min 0, width 2) and slot 4 as one exception with value 1000.
05 05 count 5, codec PATCHED00 02 E4 00 base: min 0, width 2, offsets 0 1 2 3 001 e = 108 00 positions: min 4 (zvarint 8), width 0D0 0F 00 values: min 1000 (zvarint 2000), width 0Slots 0 and 4 hold base.min. Slot 0 is not in the positions and stays 0. Slot 4 is, so it becomes 1000. The result is 0, 1, 2, 3, 1000.
Checks
Section titled “Checks”- Everything that Packed checks, three times.
countandeare within their limits.- Positions are ascending when written. A decoder rejects a position at or above
n, and point lookups binary-search the positions, so out-of-order positions give wrong results.
When writers pick it
Section titled “When writers pick it”See How writers choose a codec.
Related
Section titled “Related”- FOR and Packed integers
- ALP, which keeps exceptions in a similar way
- Column codecs