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