XDelta Compression Format
The XINA Delta (xd) compression format is a simple, high performance format for compression and decompression of a list of numeric values into a string. The compression is most efficient for data sets with frequently repeated values, or predictable value iterations.
The format consists of a few main features:
- a comma separated list of values
-
blankvalues indicating either repeating the previous value, or a static value -
"n#"indicates repeating the previous value#times - each point is a delta of the previous point (which can be applied recursively)
- transformation of values (typically just to reduce their character length, since the format is plain-text)
The format grammar is as follows:
string
-
parameters ':' values
parameters
-
parameter -
parameter ',' parameters
parameter
-
'v' integer -
'd' integer -
'd' -
'dd' -
'br' -
'b' -
'b' number -
'+' number -
'-' number -
'*' number -
'/' number
values
-
value -
value ',' values
value
-
"" -
number -
number 'n' integer -
'n' integer
number
-
integer fraction exponent
integer
-
digit -
onenine digits -
'-' digit -
'-' onenine digits
digits
-
digit -
digit digits
digit
-
'0' -
onenine
onenine
-
'1' . '9'
fraction
-
"" -
'.' digits
exponent
-
"" -
'E' sign digits -
'e' sign digits
sign
-
"" -
'+' -
'-'
The configuration of the encoding of a particular string is denoted by a comma delimited set of steps. These are:
-
b<number>- blanks are provided static value -
br- blanks repeat previous value -
d- single iteration delta -
dd- double iteration delta -
+<number>- add static value -
-<number>- subtract static value -
*<number>- multiply by static value -
/<number>- divide by static value
This is followed by a colon, and the encoded data.
For example, given the array of numbers:
1, 1, 1, 1, 2, 3, 4, 4, 4, 3, 2, 1, 0, 0, 0
One possible encoding would be:
"d,b0:1,,n2,1,n2,,,-1,n3,,"
Breaking this down:
| Dec | Enc |
|---|---|
| 1 | 1 |
| 1 | blank = d0 = 1+0 = 1 |
| 1 | n2 = previous value twice = d0 = 1+0 = 1 |
| 1 | " |
| 2 | 1 = d1 = 1+1 = 2 |
| 3 | n2 = previous value twice = d1 = 2+1 = 3 |
| 4 | " = d1 = 3+1 = 4 |
| 4 | blank = d0 = 4+0 = 4 |
| 4 | blank = d0 = 4+0 = 4 |
| 3 | -1 = d-1 = 4-1 = 3 |
| 2 | n3 = previous value thrice = d-1 = 3-1 = 2 |
| 1 | " = d-1 = 2-1 = 1 |
| 0 | " = d-1 = 1-1 = 0 |
| 0 | blank = d0 = 0+0 = 0 |
| 0 | blank = d0 = 0+0 = 0 |