//>>built
define("dojox/encoding/compression/lzw",["dojo/_base/lang","../bits"],function(d,g){var c=d.getObject("dojox.encoding.compression.lzw",!0),f=function(a){for(var b=1,c=2;a>=c;c<<=1,++b);return b};c.Encoder=function(a){this.size=a;this.init()};d.extend(c.Encoder,{init:function(){this.dict={};for(var a=0;a<this.size;++a)this.dict[String.fromCharCode(a)]=a;this.width=f(this.code=this.size);this.p=""},encode:function(a,b){var c=String.fromCharCode(a),d=this.p+c,e=0;if(d in this.dict)return this.p=d,e;
b.putBits(this.dict[this.p],this.width);0==(this.code&this.code+1)&&b.putBits(this.code++,e=this.width++);this.dict[d]=this.code++;this.p=c;return e+this.width},flush:function(a){if(0==this.p.length)return 0;a.putBits(this.dict[this.p],this.width);this.p="";return this.width}});c.Decoder=function(a){this.size=a;this.init()};d.extend(c.Decoder,{init:function(){this.codes=Array(this.size);for(var a=0;a<this.size;++a)this.codes[a]=String.fromCharCode(a);this.width=f(this.size);this.p=-1},decode:function(a){a=
a.getBits(this.width);var b;if(a<this.codes.length)b=this.codes[a],0<=this.p&&this.codes.push(this.codes[this.p]+b.substr(0,1));else{if(0==(a&a+1))return this.codes.push(""),++this.width,"";b=this.codes[this.p];b+=b.substr(0,1);this.codes.push(b)}this.p=a;return b}});return c});