// @author Andrea Giammarchi (function(cache){ /** JSON.hpack(homogeneousCollection:Array[, compression:Number]):Array * @param Array mono dimensional homogeneous collection of objects to pack * @param [Number] optional compression level from 0 to 4 - default 0 * @return Array optimized collection */ (this.JSON || (JSON = {})).hpack = function(collection, compression){ if(3 < compression){ // try evey compression level and returns the best option var i = JSON.hbest(collection), result = cache[i] ; cache = []; } else { // compress via specified level (default 0) var indexOf = Array.prototype.indexOf || function(v){for(var l=this.length,i=0;i [["k"],[0]] (9 chars against 11) // above example is not real life example and as soon // as the list will have more than an object // hpack will start to make the difference: // [{"k":0},{"k":0}] ==> [["k"],[0],[0]] (17 chars against 15) return j; }; })([]);