40 likes | 301 Views
Lempel-Ziv Encoding. BAB. CB. ABC. BABA. ABA. BA. AB. 3. 4. 5. 6. 7. 8. 9. Compress. 0. 1. 3. 3. 2. 4. 8. ABABABCBABABABCBABABABCBA Loop buffer c sent stored new buffer. 1. A. B. 0. AB (3). B. 2. B. A. 1. BA (4). A. AB. 3. A. B. 3. ABA (5).
E N D
BAB CB ABC BABA ABA BA AB 3 4 5 6 7 8 9 Compress 0 1 3 3 2 4 8 • ABABABCBABABABCBABABABCBA Loop buffer c sent stored new buffer 1 A B 0 AB (3) B 2 B A 1 BA (4) A AB 3 A B 3 ABA (5) A A 4 AB AB B 5 A 3 ABC(6) C C 6 AB 2 CB(7) B B 7 C BA A 8 B 4 BAB(8) B B 9 BA BA A 10 B BAB B 11 BA 8 BABA(9) A A 12 BAB A B C 0 1 2
0 1 3 3 2 4 8 A B C BABAB CB BAB ABCB CBA BABC ABC BABA ABA BA AB 0 1 2 3 7 4 5 6 8 12 11 9 10 13 Compress 6 9 8 • ABABABCBABABABCBABABABCBA Loop buffer c sent stored new buffer 13 A B AB 14 AB C ABC 15 ABC B 6 ABCB(10) B 16 B A BA 17 BA B BAB 18 BAB A BABA 19 BABA B 9 BABAB(11) B 20 B A BA 21 BA B BAB 22 BAB C 8 BABC(12) C
CB BA ABA ABC BABAB BAB AB BABA ABCB 11 6 8 10 3 5 9 7 4 Uncompress 0 1 3 3 2 4 8 6 9 8 7 0 • Loop Prior current in table c tmp/code printed 1 0 (A) 1 (B) Y B AB/3 B 2 1 (B) 3 (AB) Y A BA/4 AB 3 3 (AB) 3 (AB) Y A ABA/5 AB 4 3 (AB) 2 (C) Y C ABC/6 C 5 2 (C) 4 (BA) Y B CB/7 BA 6 4 (BA) 8 N B BAB/8 BAB 7 8 (BAB) 6 (ABC) Y A BABA/9 ABC 8 6 (ABC) 9 (BABA) Y B ABCB/10 BABA 9 9 (BABA) 8 (BAB) Y B BABAB/11 BAB A B C 0 1 2