-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* pass table with get parameter using lzw comrpession
- Loading branch information
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
var LZW = { | ||
compress: function (uncompressed) { | ||
"use strict"; | ||
// Build the dictionary. | ||
var i, | ||
dictionary = {}, | ||
c, | ||
wc, | ||
w = "", | ||
result = [], | ||
dictSize = 256; | ||
for (i = 0; i < 256; i += 1) { | ||
dictionary[String.fromCharCode(i)] = i; | ||
} | ||
|
||
for (i = 0; i < uncompressed.length; i += 1) { | ||
c = uncompressed.charAt(i); | ||
wc = w + c; | ||
if (dictionary[wc]) { | ||
w = wc; | ||
} else { | ||
result.push(dictionary[w]); | ||
// Add wc to the dictionary. | ||
dictionary[wc] = dictSize++; | ||
w = String(c); | ||
} | ||
} | ||
|
||
// Output the code for w. | ||
if (w !== "") { | ||
result.push(dictionary[w]); | ||
} | ||
return result; | ||
}, | ||
|
||
|
||
decompress: function (compressed) { | ||
"use strict"; | ||
// Build the dictionary. | ||
var i, | ||
dictionary = [], | ||
w, | ||
result, | ||
k, | ||
entry = "", | ||
dictSize = 256; | ||
for (i = 0; i < 256; i += 1) { | ||
dictionary[i] = String.fromCharCode(i); | ||
} | ||
|
||
w = String.fromCharCode(compressed[0]); | ||
result = w; | ||
for (i = 1; i < compressed.length; i += 1) { | ||
k = compressed[i]; | ||
if (dictionary[k]) { | ||
entry = dictionary[k]; | ||
} else { | ||
if (k === dictSize) { | ||
entry = w + w.charAt(0); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
result += entry; | ||
|
||
// Add w+entry[0] to the dictionary. | ||
dictionary[dictSize++] = w + entry.charAt(0); | ||
|
||
w = entry; | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters