1 if(!dojo._hasResource["dojox.encoding.compression.splay"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.encoding.compression.splay"] = true;
3 dojo.provide("dojox.encoding.compression.splay");
4 dojo.require("dojox.encoding.bits");
6 dojox.encoding.compression.Splay = function(n){
7 this.up = new Array(2 * n + 1);
8 this.left = new Array(n);
9 this.right = new Array(n);
13 dojo.extend(dojox.encoding.compression.Splay, {
15 for(var i = 1; i < this.up.length; this.up[i] = Math.floor((i - 1) / 2), ++i);
16 for(var i = 0; i < this.left.length; this.left[i] = 2 * i + 1, this.right[i] = 2 * i + 2, ++i);
19 var a = i + this.left.length;
33 this[a == this.left[c] ? "left" : "right"][c] = b;
42 encode: function(value, stream){
43 var s = [], a = value + this.left.length;
45 s.push(this.right[this.up[a]] == a);
50 while(s.length){ stream.putBits(s.pop() ? 1 : 0, 1); }
53 decode: function(stream){
56 a = this[stream.getBits(1) ? "right" : "left"][a];
57 }while(a < this.left.length);
58 a -= this.left.length;