Delta encoding is a way of storing or transmitting data in the form of differences (deltas) between sequential data rather than complete files; more generally this is known as data differencing. Delta encoding is sometimes called delta compression, particularly where archival histories of changes are required (e.g., in revision control software). The differences are recorded in discrete files called "deltas" or "diffs". In situations where differences are small – for example, the change of a few words in a large document or the change of a few records in a large table – delta encoding greatly reduces data redundancy. Collections of unique deltas are substantially more space-efficient than their non-encoded equivalents. From a logical point of view, the difference between two data values is the information required to obtain one value from the other – see relative entropy. The difference between identical values (under some equivalence) is often called 0 or the neutral element.
Data differencing In computer science and information theory, data differencing or differential compression is producing a technical description of the difference between two sets of data – a source and a target. Formally, a data differencing algorithm takes as input source data and target data, and produces difference data such that given the source data and the difference data, one can reconstruct the target data ("patching" the source with the difference to produce the target).
Numeric example Perhaps the simplest example is storing values of bytes as differences (deltas) between sequential values, rather than the values themselves. So, instead of (2,4,6,9,7), we would store (2,2,2,3,−2). This reduces the variance (range) of the values when neighbor samples are correlated, enabling a lower bit usage for the same data. IFF 8SVX sound format applies this encoding to raw sound data before applying compression to it. Not even all 8-bit sound samples compress better when delta encoded, and the usability of delta encoding is even smaller for 16-bit and better samples. Therefore, compression algorithms often choose to delta encode only when the compression is better than without. However, in video compression, delta frames can considerably reduce frame size and are used in virtually every video compression codec. These frames require a different type of delta calculation.
Definition
Numeric The delta of numeric values is straightforwardly defined by subtraction, as shown in the example above. Due to the property of arithmetic operations, the numeric delta is symmetric: if the latter value b is known, it is possible to apply the delta b−a in reverse to obtain the previous value a. It is also possible to produce a numeric "delta of deltas". This can be useful if the underlying data is generated by a process resembling f(x)=ax+b, as second-order delta would flatten the data to a string of zeros. Timestamps often behave this way. Even higher-order deltas may be useful for real-life data: for example, the measured distance (pseudorange) to a navigation satellite over time is best compressed using a third-order delta, a "delta of deltas of deltas". In addition to subtraction, the bitwise exclusive or (XOR) also produces a symmetric delta. Time series databases often use the XOR operation as a delta between floating-point numbers as it produces easily compressible differences consisting of mostly zero bits. Another variation is to change the distance between elements used for the delta operation: instead of calculating b−a in the sequence (a,b,c,d), a "distance-2" delta would calculate c−a. This is seen in the "delta" filter of xz.
Sample C code The following C code performs a simple form of delta encoding and decoding on a sequence of characters:
Collections For the difference between sequences or sets of values (e.g. character-strings and images), a delta can be defined in 2 ways, symmetric delta and directed delta. A symmetric delta between two sets includes enough information to make it reversible:
Δ(𝑣𝑒𝑟𝑠𝑖𝑜𝑛1,𝑣𝑒𝑟𝑠𝑖𝑜𝑛2)=(𝑣𝑒𝑟𝑠𝑖𝑜𝑛1∖𝑣𝑒𝑟𝑠𝑖𝑜𝑛2)∪(𝑣𝑒𝑟𝑠𝑖𝑜𝑛2∖𝑣𝑒𝑟𝑠𝑖𝑜𝑛1). The difference between two sequences is analogously defined, except that information for locating the additions and removals are added. In computer implementations, it is exemplified by the output of diff (in the default, unified, and context modes): instructions in the form of "at position x, replace (old content) with (new content)". A directed delta, also called a change, is a sequence of (elementary) change operations which, when applied to 𝑣𝑒𝑟𝑠𝑖𝑜𝑛1, yields another, 𝑣𝑒𝑟𝑠𝑖𝑜𝑛2 (note the correspondence to transaction logs in databases). In computer implementations, they typically take the form of a language with two commands: copy data from 𝑣𝑒𝑟𝑠𝑖𝑜𝑛1 and write literal data. An example is the output of diff in the edit script mode.
Variants A variation of delta encoding which encodes differences between the prefixes or suffixes of strings is called incremental encoding. It is particularly effective for sorted lists with small differences between strings, such as a list of words from a dictionary.
Implementation issues The nature of the data to be encoded influences the effectiveness of a particular compression algorithm. Delta encoding performs best when data has small or constant variation; for an unsorted data set, there may be little to no compression possible with this method. In delta encoded transmission over a network where only a single copy of the file is available at each end of the communication channel, special error control codes are used to detect which parts of the file have changed since its previous version. For example, rsync uses a rolling checksum algorithm based on Mark Adler's adler-32 checksum.
Examples One of the best-known examples of data differencing is the diff utility, which produces line-by-line differences of text files (and in some implementations, binary files, thus being a general-purpose differencing tool). Differencing of general binary files goes under the rubric of delta encoding, with a widely used example being the algorithm used in rsync. A standardized generic differencing format is VCDIFF, implemented in such utilities as Xdelta version 3. A high-efficiency (small patch files) differencing program is bsdiff, which uses bzip2 as a final compression step on the generated delta.
Binary delta compression
… excerpt ends here. Continue reading the full article.