lib/Bzip2.js
function(selectors, groups, input) {
  var i, j, k;
  for (i=0, k=0; i<input.length; i+=GROUP_SIZE) {
    var groupSize = Math.min(GROUP_SIZE, input.length - i);
    var best = 0, bestCost = groups[0].cost(input, i, groupSize);
    for (j=1; j<groups.length; j++) {
      var groupCost = groups[j].cost(input, i, groupSize);
      if (groupCost < bestCost) {
        best = j; bestCost = groupCost;
      }
    }
    selectors[k++] = best;
  }
}
function(selectors, groups, input) {
  var i, j, k;
  for (i=0, k=0; i<input.length; i+=GROUP_SIZE) {
    var groupSize = Math.min(GROUP_SIZE, input.length - i);
    var best = 0, bestCost = groups[0].cost(input, i, groupSize);
    for (j=1; j<groups.length; j++) {
      var groupCost = groups[j].cost(input, i, groupSize);
      if (groupCost < bestCost) {
        best = j; bestCost = groupCost;
      }
    }
    selectors[k++] = best;
  }
}
function ( selectors , groups , input ) { var i , j , k ; for ( i = 0 , k = 0 ; i < input . length ; i += GROUP_SIZE ) { var groupSize = Math . min ( GROUP_SIZE , input . length - i ) ; var best = 0 , bestCost = groups [ 0 ] . cost ( input , i , groupSize ) ; for ( j = 1 ; j < groups . length ; j ++ ) { var groupCost = groups [ j ] . cost ( input , i , groupSize ) ; if ( groupCost < bestCost ) { best = j ; bestCost = groupCost ; } } selectors [ k ++ ] = best ; } }
divide the input into groups at most GROUP_SIZE symbols long. assign each group to the Huffman table which compresses it best.
divide the input into groups at most GROUP_SIZE symbols long . assign each group to the Huffman table which compresses it best .