- function Decompress(srctext){
- var ht = new Array;
- var used = 128;
- var intLeftOver = 0;
- var intOutputCode = 0;
- var ccode = 0;
- var pcode = 0;
- var key = 0;
- var Outbuff = "";
- for(var i=0;i <used;i++){ ht[i] = String.fromCharCode(i);}
- for(i=0;i<srctext.length;i++){
- intLeftOver += 16;
- intOutputCode <<= 16;
- intOutputCode |= srctext.charCodeAt(i);
- while(1){
- if(intLeftOver >= 12){
- ccode = intOutputCode >> (intLeftOver - 12);
- if( typeof( key = ht[ccode] ) != "undefined"){
- Outbuff += key;
- if(used > 128){
- ht[ht.length] = ht[pcode] + key.substr(0, 1);
- }
- pcode = ccode;
- }else{
- key = ht[pcode] + ht[pcode].substr(0, 1);
- Outbuff += key;
- ht[ht.length] = ht[pcode] + key.substr(0, 1);
- pcode = ht.length - 1;
- }
- used ++;
- intLeftOver -= 12;
- intOutputCode &= (Math.pow(2,intLeftOver) - 1);
- }else{break;}
- }
- }
- return Outbuff;
- }
- function HashTableElement(k,c){
- this.key = k;
- this.code = c;
- }
- function HashTable(){
- this.ht = new Array(4099);
- this.Search = function(keyword){
- var arr = this.ht[keyword % 4099];
- if(typeof(arr) != "undefined"){
- for(i = 0; i < arr.length; i ++){
- if(arr[i].key == keyword)
- return arr[i].code;
- }
- }
- return null;
- }
- this.Insert = function(lKey,lCode){
- var e = new HashTableElement(lKey,lCode);
- if(typeof this.ht[e.key % 4099] == "undefined"){
- this.ht[e.key % 4099] = [];
- }
- this.ht[e.key%4099].push(e);
- }
LZW压缩算法js版
最新推荐文章于 2025-05-24 13:20:40 发布