summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/encoding/compression
diff options
context:
space:
mode:
Diffstat (limited to 'js/dojo-1.6/dojox/encoding/compression')
-rw-r--r--js/dojo-1.6/dojox/encoding/compression/lzw.js101
-rw-r--r--js/dojo-1.6/dojox/encoding/compression/lzw.xd.js106
-rw-r--r--js/dojo-1.6/dojox/encoding/compression/splay.js74
-rw-r--r--js/dojo-1.6/dojox/encoding/compression/splay.xd.js79
4 files changed, 360 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojox/encoding/compression/lzw.js b/js/dojo-1.6/dojox/encoding/compression/lzw.js
new file mode 100644
index 0000000..6648056
--- /dev/null
+++ b/js/dojo-1.6/dojox/encoding/compression/lzw.js
@@ -0,0 +1,101 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.encoding.compression.lzw"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.encoding.compression.lzw"] = true;
+dojo.provide("dojox.encoding.compression.lzw");
+dojo.require("dojox.encoding.bits");
+
+
+dojo.getObject("encoding.compression.lzw", true, dojox);
+
+(function(){
+ var _bits = function(x){
+ var w = 1;
+ for(var v = 2; x >= v; v <<= 1, ++w);
+ return w;
+ };
+
+ dojox.encoding.compression.lzw.Encoder = function(n){
+ this.size = n;
+ this.init();
+ };
+
+ dojo.extend(dojox.encoding.compression.lzw.Encoder, {
+ init: function(){
+ this.dict = {};
+ for(var i = 0; i < this.size; ++i){
+ this.dict[String.fromCharCode(i)] = i;
+ }
+ this.width = _bits(this.code = this.size);
+ this.p = "";
+ },
+ encode: function(value, stream){
+ var c = String.fromCharCode(value), p = this.p + c, r = 0;
+ // if already in the dictionary
+ if(p in this.dict){
+ this.p = p;
+ return r;
+ }
+ stream.putBits(this.dict[this.p], this.width);
+ // if we need to increase the code length
+ if((this.code & (this.code + 1)) == 0){
+ stream.putBits(this.code++, r = this.width++);
+ }
+ // add new string
+ this.dict[p] = this.code++;
+ this.p = c;
+ return r + this.width;
+ },
+ flush: function(stream){
+ if(this.p.length == 0){
+ return 0;
+ }
+ stream.putBits(this.dict[this.p], this.width);
+ this.p = "";
+ return this.width;
+ }
+ });
+
+ dojox.encoding.compression.lzw.Decoder = function(n){
+ this.size = n;
+ this.init();
+ };
+
+ dojo.extend(dojox.encoding.compression.lzw.Decoder, {
+ init: function(){
+ this.codes = new Array(this.size);
+ for(var i = 0; i < this.size; ++i){
+ this.codes[i] = String.fromCharCode(i);
+ }
+ this.width = _bits(this.size);
+ this.p = -1;
+ },
+ decode: function(stream){
+ var c = stream.getBits(this.width), v;
+ if(c < this.codes.length){
+ v = this.codes[c];
+ if(this.p >= 0){
+ this.codes.push(this.codes[this.p] + v.substr(0, 1));
+ }
+ }else{
+ if((c & (c + 1)) == 0){
+ this.codes.push("");
+ ++this.width;
+ return "";
+ }
+ var x = this.codes[this.p];
+ v = x + x.substr(0, 1);
+ this.codes.push(v);
+ }
+ this.p = c;
+ return v;
+ }
+ });
+})();
+
+}
diff --git a/js/dojo-1.6/dojox/encoding/compression/lzw.xd.js b/js/dojo-1.6/dojox/encoding/compression/lzw.xd.js
new file mode 100644
index 0000000..88f3107
--- /dev/null
+++ b/js/dojo-1.6/dojox/encoding/compression/lzw.xd.js
@@ -0,0 +1,106 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.encoding.compression.lzw"],
+["require", "dojox.encoding.bits"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.encoding.compression.lzw"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.encoding.compression.lzw"] = true;
+dojo.provide("dojox.encoding.compression.lzw");
+dojo.require("dojox.encoding.bits");
+
+
+dojo.getObject("encoding.compression.lzw", true, dojox);
+
+(function(){
+ var _bits = function(x){
+ var w = 1;
+ for(var v = 2; x >= v; v <<= 1, ++w);
+ return w;
+ };
+
+ dojox.encoding.compression.lzw.Encoder = function(n){
+ this.size = n;
+ this.init();
+ };
+
+ dojo.extend(dojox.encoding.compression.lzw.Encoder, {
+ init: function(){
+ this.dict = {};
+ for(var i = 0; i < this.size; ++i){
+ this.dict[String.fromCharCode(i)] = i;
+ }
+ this.width = _bits(this.code = this.size);
+ this.p = "";
+ },
+ encode: function(value, stream){
+ var c = String.fromCharCode(value), p = this.p + c, r = 0;
+ // if already in the dictionary
+ if(p in this.dict){
+ this.p = p;
+ return r;
+ }
+ stream.putBits(this.dict[this.p], this.width);
+ // if we need to increase the code length
+ if((this.code & (this.code + 1)) == 0){
+ stream.putBits(this.code++, r = this.width++);
+ }
+ // add new string
+ this.dict[p] = this.code++;
+ this.p = c;
+ return r + this.width;
+ },
+ flush: function(stream){
+ if(this.p.length == 0){
+ return 0;
+ }
+ stream.putBits(this.dict[this.p], this.width);
+ this.p = "";
+ return this.width;
+ }
+ });
+
+ dojox.encoding.compression.lzw.Decoder = function(n){
+ this.size = n;
+ this.init();
+ };
+
+ dojo.extend(dojox.encoding.compression.lzw.Decoder, {
+ init: function(){
+ this.codes = new Array(this.size);
+ for(var i = 0; i < this.size; ++i){
+ this.codes[i] = String.fromCharCode(i);
+ }
+ this.width = _bits(this.size);
+ this.p = -1;
+ },
+ decode: function(stream){
+ var c = stream.getBits(this.width), v;
+ if(c < this.codes.length){
+ v = this.codes[c];
+ if(this.p >= 0){
+ this.codes.push(this.codes[this.p] + v.substr(0, 1));
+ }
+ }else{
+ if((c & (c + 1)) == 0){
+ this.codes.push("");
+ ++this.width;
+ return "";
+ }
+ var x = this.codes[this.p];
+ v = x + x.substr(0, 1);
+ this.codes.push(v);
+ }
+ this.p = c;
+ return v;
+ }
+ });
+})();
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/encoding/compression/splay.js b/js/dojo-1.6/dojox/encoding/compression/splay.js
new file mode 100644
index 0000000..3df3743
--- /dev/null
+++ b/js/dojo-1.6/dojox/encoding/compression/splay.js
@@ -0,0 +1,74 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.encoding.compression.splay"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.encoding.compression.splay"] = true;
+dojo.provide("dojox.encoding.compression.splay");
+dojo.require("dojox.encoding.bits");
+
+
+dojo.getObject("encoding.compression.splay", true, dojox);
+
+dojox.encoding.compression.Splay = function(n){
+ this.up = new Array(2 * n + 1);
+ this.left = new Array(n);
+ this.right = new Array(n);
+ this.reset();
+};
+
+dojo.extend(dojox.encoding.compression.Splay, {
+ reset: function(){
+ for(var i = 1; i < this.up.length; this.up[i] = Math.floor((i - 1) / 2), ++i);
+ for(var i = 0; i < this.left.length; this.left[i] = 2 * i + 1, this.right[i] = 2 * i + 2, ++i);
+ },
+ splay: function(i){
+ var a = i + this.left.length;
+ do{
+ var c = this.up[a];
+ if(c){ // root
+ // rotated pair
+ var d = this.up[c];
+ // swap descendants
+ var b = this.left[d];
+ if(c == b){
+ b = this.right[d];
+ this.right[d] = a;
+ } else {
+ this.left[d] = a;
+ }
+ this[a == this.left[c] ? "left" : "right"][c] = b;
+ this.up[a] = d;
+ this.up[b] = c;
+ a = d;
+ }else{
+ a = c;
+ }
+ }while(a); // root
+ },
+ encode: function(value, stream){
+ var s = [], a = value + this.left.length;
+ do{
+ s.push(this.right[this.up[a]] == a);
+ a = this.up[a];
+ }while(a); // root
+ this.splay(value);
+ var l = s.length;
+ while(s.length){ stream.putBits(s.pop() ? 1 : 0, 1); }
+ return l;
+ },
+ decode: function(stream){
+ var a = 0; // root;
+ do{
+ a = this[stream.getBits(1) ? "right" : "left"][a];
+ }while(a < this.left.length);
+ a -= this.left.length;
+ this.splay(a);
+ return a;
+ }
+});
+
+}
diff --git a/js/dojo-1.6/dojox/encoding/compression/splay.xd.js b/js/dojo-1.6/dojox/encoding/compression/splay.xd.js
new file mode 100644
index 0000000..4655542
--- /dev/null
+++ b/js/dojo-1.6/dojox/encoding/compression/splay.xd.js
@@ -0,0 +1,79 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.encoding.compression.splay"],
+["require", "dojox.encoding.bits"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.encoding.compression.splay"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.encoding.compression.splay"] = true;
+dojo.provide("dojox.encoding.compression.splay");
+dojo.require("dojox.encoding.bits");
+
+
+dojo.getObject("encoding.compression.splay", true, dojox);
+
+dojox.encoding.compression.Splay = function(n){
+ this.up = new Array(2 * n + 1);
+ this.left = new Array(n);
+ this.right = new Array(n);
+ this.reset();
+};
+
+dojo.extend(dojox.encoding.compression.Splay, {
+ reset: function(){
+ for(var i = 1; i < this.up.length; this.up[i] = Math.floor((i - 1) / 2), ++i);
+ for(var i = 0; i < this.left.length; this.left[i] = 2 * i + 1, this.right[i] = 2 * i + 2, ++i);
+ },
+ splay: function(i){
+ var a = i + this.left.length;
+ do{
+ var c = this.up[a];
+ if(c){ // root
+ // rotated pair
+ var d = this.up[c];
+ // swap descendants
+ var b = this.left[d];
+ if(c == b){
+ b = this.right[d];
+ this.right[d] = a;
+ } else {
+ this.left[d] = a;
+ }
+ this[a == this.left[c] ? "left" : "right"][c] = b;
+ this.up[a] = d;
+ this.up[b] = c;
+ a = d;
+ }else{
+ a = c;
+ }
+ }while(a); // root
+ },
+ encode: function(value, stream){
+ var s = [], a = value + this.left.length;
+ do{
+ s.push(this.right[this.up[a]] == a);
+ a = this.up[a];
+ }while(a); // root
+ this.splay(value);
+ var l = s.length;
+ while(s.length){ stream.putBits(s.pop() ? 1 : 0, 1); }
+ return l;
+ },
+ decode: function(stream){
+ var a = 0; // root;
+ do{
+ a = this[stream.getBits(1) ? "right" : "left"][a];
+ }while(a < this.left.length);
+ a -= this.left.length;
+ this.splay(a);
+ return a;
+ }
+});
+
+}
+
+}};});