BWT Data Compression Algorithm

Source: Internet
Author: User

Urrower-wheeler Transformation

In 1994, Michael burrows and David Wheeler jointly proposed a new universal data compression algorithm, Burrows-wheeler transformation, in a block-sorting lossless data compression algorithm.

The BWT algorithms designed by burrows and Wheeler are different from those designed by all common compression algorithms in the past. Existing well-known compression algorithms are used to process data stream models. One or more bytes are read at a time, and BWT makes it possible to process block data. The core idea of this algorithm is to sort and transform the character matrix obtained after string rotation. For general text applications, such as English text, the string is often used. After BW conversion, all t is moved to the end and aggregated, in this way, the transformed string is compressed using the general statistical compression model (Huffman coding, LZ algorithm, and PPM algorithm) to obtain a better compression ratio.

 

Encoding Transformation

By moving the original string cyclically, sort the shifted strings in the lexicographically ascending order. The last character in the string, which is output in sequence. The position of the original sequence in the sorting sequence is also output.

Take the string "^ banana @" as an example. The steps for converting to "BNN ^ aa @ A" are as follows:

Transform
Input All cyclic shifts Sort all rows Output
^BANANA@
^BANANA@@^BANANAA@^BANANNA@^BANAANA@^BANNANA@^BAANANA@^BBANANA@^
ANANA@^BANA@^BANA@^BANANBANANA@^NANA@^BANA@^BANA^BANANA@@^BANANA
BNN^AA@A

6 is the original string in the sorting sequence (all values start from 0 without special instructions );

 

The algorithm is described as follows:


 function BWT (string s)   create a table, rows are all possible rotations of s   sort rows alphabetically   return (last column of the table)

 

The C language code is as follows:

 

 

# Include <stdio. h> <br/> # include <stdlib. h> <br/> # include <string. h> <br/> # define BLOCK_SIZE 200000 <br/> long length; // String length <br/> unsigned char buffer [BLOCK_SIZE]; // original string <br/> int indices [BLOCK_SIZE]; <br/> int memcmp_signed = 0; <br/> int _ cdecl bounded_cmp (const unsigned int * i1, const unsigned int * i2) <br/>{< br/> int base = length; <br/> char I = * i1, j = * i2; </p> <p> while (base --) <br/> {<br/> if (* (buffer + I) = * (buffer + j )) <br/>{< br/> I ++; <br/> j ++; <br/> I % = length; <br/> j % = length; <br/>}< br/> else <br/> {<br/> return * (buffer + I)-* (buffer + j ); <br/>}< br/> return 0; <br/>}< br/> main (int argc, char * argv []) <br/>{< br/> int debug = 0; <br/> int I; <br/> (;;) <br/>{< br/> gets (char *) buffer); // enter the string to be processed <br/> length = strlen (char *) buffer ); <br/> printf ("Ming BWT on % ld bytes/n", length); </p> <p> for (I = 0; I <length; I ++) <br/>{< br/> indices [I] = I; // The string after the I-th loop starts from the I-th of the original string <br/>}</p> <p> // sorts the sequence after the loop moves <br /> qsort (indices, (int) (length), sizeof (int), (int (*) (const void *, const void *) bounded_cmp); </p> <p> long last; <br/> for (I = 0; I <length; I ++) <br/> {<br/> if (indices [I] = 0) <br/>{< br/> last = I; <br/> putchar (buffer [length-1]); <br/>}< br/> else <br/> {<br/> putchar (buffer [indices [I]-1]); <br/>}< br/> printf ("/nlast = % ld/n", last ); <br/>}< br/> return 0; <br/>}< br/> 

 

Decoding process

To be continued ......

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.