표현 방법
원본 데이터 : Blah blah b압축 결과 : Blah b[Distance=5,Length=5] (탈출문자)(거리)(길이)
Lempel-Ziv 압축 알고리즘
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | void compress(FILE* fin) { initialize(code table); buffer=string consisting of first character from the file. while( (c=getc(fin))!=EOF ) { _string=concat(buffer,c); search for _string in the code table; if found buffer=_string; else { send the code associated with buffer; assgn a code to _string; store both in the code table; buffer=string consisting of one character c; } } send the code associated with buffer; } | cs |
Lempel-Ziv 복원 알고리즘
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | void decompress { initialize(code table); receive first code, call it prior; pritnf the string associated with prior; while(true) { receive code, call it current; if no code then break; search for current in the code table; if not found { c=first character of string associated with prior; _string = concat(string associated with prior, c); assign a code to _string; store both in the code table; print _string; } else { c=first character of string associated with prior; _string=concat(string associated with prior,c); assign a code to _string; store both in the code table; print string associated with current; } prior=current; } } | cs |
복원 예제
ZLIB 로 메모리에 압축 하기 (0) | 2021.01.06 |
---|---|
ZLIB 사용하여 메모리에 압축 풀기 (0) | 2021.01.06 |
GZIP 구조 (0) | 2017.10.14 |
Run Length Encoding(1) (0) | 2017.10.14 |
PKZIP 구조(2) (0) | 2016.01.19 |
댓글 영역