16,019,957 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Visual Basic questions
View Javascript questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by reena_c (Top 21 by date)
reena_c
13-Aug-12 6:57am
View
Thanks its work for me....
reena_c
13-Aug-12 6:18am
View
i want to compress data . i am sending my data as parameter in js function, where i can inflate data from js function
reena_c
10-Aug-12 1:58am
View
can i decompress the compressed data using rawinflate.js in C#
reena_c
9-Aug-12 6:35am
View
thanks
reena_c
9-Aug-12 6:19am
View
code is here
/*
* $Id: rawinflate.js,v 0.2 2009/03/01 18:32:24 dankogai Exp $
*
* original:
* http://www.onicos.com/staff/iz/amuse/javascript/expert/inflate.txt
*/
(function(){
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0.0.1
* LastModified: Dec 25 1999
*/
/* Interface:
* data = zip_inflate(src);
*/
/* constant parameters */
var zip_WSIZE = 32768; // Sliding Window size
var zip_STORED_BLOCK = 0;
var zip_STATIC_TREES = 1;
var zip_DYN_TREES = 2;
/* for inflate */
var zip_lbits = 9; // bits in base literal/length lookup table
var zip_dbits = 6; // bits in base distance lookup table
var zip_INBUFSIZ = 32768; // Input buffer size
var zip_INBUF_EXTRA = 64; // Extra buffer
/* variables (inflate) */
var zip_slide;
var zip_wp; // current position in slide
var zip_fixed_tl = null; // inflate static
var zip_fixed_td; // inflate static
var zip_fixed_bl, fixed_bd; // inflate static
var zip_bit_buf; // bit buffer
var zip_bit_len; // bits in bit buffer
var zip_method;
var zip_eof;
var zip_copy_leng;
var zip_copy_dist;
var zip_tl, zip_td; // literal/length and distance decoder tables
var zip_bl, zip_bd; // number of bits decoded by tl and td
var zip_inflate_data;
var zip_inflate_pos;
/* constant tables (inflate) */
var zip_MASK_BITS = new Array(
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff);
// Tables for deflate from PKZIP's appnote.txt.
var zip_cplens = new Array( // Copy lengths for literal codes 257..285
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);
/* note: see note #13 above about the 258 in this list. */
var zip_cplext = new Array( // Extra bits for literal codes 257..285
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99); // 99==invalid
var zip_cpdist = new Array( // Copy offsets for distance codes 0..29
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577);
var zip_cpdext = new Array( // Extra bits for distance codes
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13);
var zip_border = new Array( // Order of the bit length code lengths
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
/* objects (inflate) */
var zip_HuftList = function() {
this.next = null;
this.list = null;
}
var zip_HuftNode = function() {
this.e = 0; // number of extra bits or operation
this.b = 0; // number of bits in this code or subcode
// union
this.n = 0; // literal, length base, or distance base
this.t = null; // (zip_HuftNode) pointer to next level of table
}
var zip_HuftBuild = function(b, // code lengths in bits (all assumed <= BMAX)
n, // number of codes (assumed <= N_MAX)
s, // number of simple-valued codes (0..s-1)
d, // list of base values for non-simple codes
e, // list of extra bits for non-simple codes
mm // maximum lookup bits
) {
this.BMAX = 16; // maximum bit length of any code
this.N_MAX = 288; // maximum number of codes in any set
this.status = 0; // 0: success, 1: incomplete table, 2: bad input
this.root = null; // (zip_HuftList) starting table
this.m = 0; // maximum lookup bits, returns actual
/* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return zero on success, one if
the given code set is incomplete (the tables are still built in this
case), two if the input is invalid (all zero length codes or an
oversubscribed set of lengths), and three if not enough memory.
The code with value 256 is special, and the tables are constructed
so that no bits beyond that code are fetched when that code is
reena_c
9-Aug-12 3:26am
View
Deleted
can use same algo to compress text in javascript and decompress in C#
reena_c
8-Aug-12 8:20am
View
thanks
reena_c
8-Aug-12 7:49am
View
yes
reena_c
8-Aug-12 7:36am
View
i want compress my string text using javascript and decompress in c#
reena_c
8-Aug-12 7:34am
View
thanks
reena_c
8-Aug-12 7:08am
View
I used huffman
reena_c
8-Aug-12 7:07am
View
do you have any other algo for string compression in javascript...
reena_c
8-Aug-12 7:02am
View
Deleted
I want to compress my text in jacascript
reena_c
8-Aug-12 6:17am
View
Deleted
i'l try
reena_c
8-Aug-12 6:16am
View
i want in C#
reena_c
8-Aug-12 6:15am
View
thanks
reena_c
8-Aug-12 6:12am
View
thanks
reena_c
8-Aug-12 6:09am
View
simply want to my compressed data in original format..above my javascript compression format , now i want decompress
reena_c
8-Aug-12 6:07am
View
i got error
reena_c
8-Aug-12 6:01am
View
Node not recognize in c# why
reena_c
8-Aug-12 5:21am
View
my javascript code here
function compress()
{
var input = document.getElementById("input").value;
var output_str = document.getElementById('<%= OutPutTB.ClientID %>');
var probabilities = getProbabilities(input);
var codes = getCodes(probabilities);
var output = compressHuffman(input, codes);
output_str.value=output;
}
function sortNumberAsc(a, b) {
return a[1] - b[1];
}
function getCodes(prob) {
var tree = new Array();
var secondTree = new Array();
this.getNext = function() {
if (tree.length > 0 && secondTree.length > 0
&& tree[0].prob < secondTree[0].prob)
return tree.shift();
if (tree.length > 0 && secondTree.length > 0
&& tree[0].prob > secondTree[0].prob)
return secondTree.shift();
if (tree.length > 0)
return tree.shift();
return secondTree.shift();
}
var sortedProb = new Array();
var codes = new Array();
var x = 0;
for (var elem in prob) {
sortedProb[x] = new Array(elem, prob[elem]);
x = x + 1;
}
sortedProb = sortedProb.sort(sortNumberAsc);
x = 0;
for (var elem in sortedProb) {
tree[x] = new node();
tree[x].prob = sortedProb[elem][1];
tree[x].value = sortedProb[elem][0];
x = x + 1;
}
while (tree.length + secondTree.length > 1) {
var left = getNext();
var right = getNext();
var newnode = new node();
newnode.left = left;
newnode.right = right;
newnode.prob = left.prob + right.prob;
newnode.left.parent = newnode;
newnode.right.parent = newnode;
secondTree.push(newnode);
}
var currentnode = secondTree[0];
var code = "";
while (currentnode) {
if (currentnode.value) {
codes[currentnode.value] = code;
code = code.substr(0, code.length - 1);
currentnode.visited = true;
currentnode = currentnode.parent;
}
else if (!currentnode.left.visited) {
currentnode = currentnode.left;
code += "0";
}
else if (!currentnode.right.visited) {
currentnode = currentnode.right;
code += "1";
}
else {
currentnode.visited = true;
currentnode = currentnode.parent;
code = code.substr(0, code.length - 1);
}
}
return codes;
}
function node() {
this.left = null;
this.right = null;
this.prob = null;
this.value = null;
this.code = "";
this.parent = null;
this.visited = false;
}
function compressHuffman(input, codes) {
var output = input.split("");
for (var elem in output) {
output[elem] = codes[output[elem]];
}
return output.join("");
}
function getProbabilities(input) {
var prob = new Array();
var x = 0;
var len = input.length;
while (x < len) {
var chr = input.charAt(x);
if (prob[chr]) {
prob[chr] = prob[chr] + 1;
}
else {
prob[chr] = 1;
}
x++;
}
for (var elem in prob) {
prob[elem] = prob[elem] / len;
}
return prob;
}
Show More