How big should the nth chunk be?
165385
protected int chunkSize(int n) {
        int power = (n == 0 || n == 1)
                    ? initialChunkPower
                    : Math.min(initialChunkPower + n - 1, AbstractSpinedBuffer.MAX_CHUNK_POWER);
        return 1 << power;
    }
265547
private byte[] alloc() {
        position = 0;
        chunk++;
        
        if (chunk >= pool.size()) {
            byte[] bytes = new byte[chunk == 0 ? initialSize : incrementalSize];
            pool.add(bytes);
        }
        
        return chunk();
    }
819035
def chunks(l, n):
    
    for i in _range(0, len(l), n):
        yield l[i:i + n]
1099154
function(self, chunkNumber, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  options = options || self.writeConcern;
  options.readPreference = self.readPreference;
  // Get the nth chunk
  self
    .chunkCollection()
    .findOne({ files_id: self.fileId, n: chunkNumber }, options, function(err, chunk) {
      if (err) return callback(err);

      var finalChunk = chunk == null ? {} : chunk;
      callback(null, new Chunk(self, finalChunk, self.writeConcern));
    });
}
1299284
public void ensureCapacity(int n)
        throws IOException
    {
        // Do we have space?
        if (n>capacity())
        {
            // Make a bigger buffer if we are allowed.
            if (_fixed)
                throw new IllegalStateException("Fixed");
                
            int new_size = ((n+_preReserve+_postReserve+4095)/4096)*4096;
            
            byte[] old = _buf;
            _buf = new byte[new_size];
            if (_pos>_start)
                System.arraycopy(old,_start,_buf,_start,_pos-_start);
            if (!_resized)
                ByteArrayPool.returnByteArray(old);
                
            _end=_buf.length-_postReserve;
            _resized=true;
        }
    }
903799
public long numericChunkRollup(Chunk c, long start, long checksum) {
    long pinfs=0, ninfs=0, naCnt=0, nzCnt=0;
    // pull (some) members into local variables for speed
    boolean isInt = _rs._isInt;
    boolean hasNA = c.hasNA();
    boolean hasFloat = c.hasFloat();
    double dmin = _rs._mins[_rs._mins.length-1];
    double dmax = _rs._maxs[_rs._maxs.length-1];

    assert(_rs._pinfs == 0); assert(_rs._ninfs == 0); assert(_rs._naCnt == 0); assert(_rs._nzCnt == 0);
    assert(dmin == Double.MAX_VALUE); assert(dmax == -Double.MAX_VALUE);

    long rows = 0; //count of non-NA rows, might be >0 for sparse chunks (all 0s are already processed outside)
    double mean = 0; //mean of non-NA rows, will be 0 for all 0s of sparse chunks
    double M2 = 0; //variance of non-NA rows, will be 0 for all 0s of sparse chunks

    // loop over all values for dense chunks, but only the non-zeros for sparse chunks
    for (int i = c.nextNZ(-1); i < c._len; i = c.nextNZ(i)) {
      if (hasNA && c.isNA(i)) naCnt++;
      else {
        double x = c.atd(i);
        long l = hasFloat ? Double.doubleToRawLongBits(x) : c.at8(i);
        if (l != 0) // ignore 0s in checksum to be consistent with sparse chunks
          checksum ^= (17 * (start + i)) ^ 23 * l;
        if (x == Double.POSITIVE_INFINITY) pinfs++;
        else if (x == Double.NEGATIVE_INFINITY) ninfs++;
        else {
          if (x != 0) nzCnt++;
          if (x < dmin) dmin = _rs.min(x);
          if (x > dmax) dmax = _rs.max(x);
          if (isInt) isInt = (long)x == x;
          rows++;
          double delta = x - mean;
          mean += delta / rows;
          M2 += delta * (x - mean);
        }
      }
    }

    // write back local variables into members
    _rs._pinfs = pinfs;
    _rs._ninfs = ninfs;
    _rs._naCnt = naCnt;
    _rs._nzCnt = nzCnt;
    _rs._rows += rows; // add to pre-filled value for sparse chunks
    _rs._isInt = isInt;
    _rs._mean = mean;
    _rs._sigma = M2;
    return checksum;
  }
1452
def size
      80 + Bitcoin.pack_var_int(transactions.size).bytesize +
          transactions.inject(0){|sum, tx| sum + (tx.witness? ? tx.serialize_witness_format.bytesize : tx.serialize_old_format.bytesize)}
    end
945137
def calc_intsize(self):
        

        # assume first cross blob starts after headxml and second is one int of bytes later
        for k in self.binarychunks.iterkeys():
            if int(k.split('/')[3]) == 1 and 'cross' in k.split('/')[-1]:
                headsize = self.binarychunks[k]
                break
        for k in self.binarychunks.iterkeys():
            if int(k.split('/')[3]) == 2 and 'cross' in k.split('/')[-1]:
                intsize = self.binarychunks[k] - headsize
                break

        return (headsize, intsize)
341329
function chunkLength (chunk, encoding) {
  if (!chunk) {
    return 0
  }

  return !Buffer.isBuffer(chunk)
    ? Buffer.byteLength(chunk, encoding)
    : chunk.length
}
618221
def chunks(data, chunk_size):
    
    for i in xrange(0, len(data), chunk_size):
        yield data[i:i+chunk_size]
779705
def split_size(size):
    ''''''
    rem = size % CHUNK_SIZE
    if rem == 0:
        cnt = size // CHUNK_SIZE
    else:
        cnt = size // CHUNK_SIZE + 1

    chunks = []
    for i in range(cnt):
        pos = i * CHUNK_SIZE
        if i == cnt - 1:
            disp = size - pos
        else:
            disp = CHUNK_SIZE
        chunks.append((pos, disp))
    return chunks
160844
def _chunk(iterable, size):
    """"""
    # We're going to use some star magic to chunk the iterable. We create a
    # copy of the iterator size times, then pull a value from each to form a
    # chunk. The last chunk may have some trailing Nones if the length of the
    # iterable isn't a multiple of size, so we filter them out.

    args = (iter(iterable),) * size

    return (
        # pylint: disable=star-args
        itertools.takewhile(lambda x: x is not None, group)
        for group in itertools.zip_longest(*args)
    )
403628
def data_chunk(data, chunk, with_overlap=False):
    """"""
    assert isinstance(chunk, tuple)
    if len(chunk) == 2:
        i, j = chunk
    elif len(chunk) == 4:
        if with_overlap:
            i, j = chunk[:2]
        else:
            i, j = chunk[2:]
    else:
        raise ValueError("'chunk' should have 2 or 4 elements, "
                         "not {0:d}".format(len(chunk)))
    return data[i:j, ...]
592005
def _ilshift(self, n):
        """"""
        assert 0 < n <= self.len
        self._append(Bits(n))
        self._truncatestart(n)
        return self
926663
def add_size(self, n):
        
        self.packet.write(struct.pack('>I', n))
        return self
606007
def split_into(max_num_chunks, list_to_chunk):
    
    max_chunk_size = math.ceil(len(list_to_chunk) / max_num_chunks)
    return chunks_of(max_chunk_size, list_to_chunk)
805812
def _chunk_with_padding(self, iterable, n, fillvalue=None):
        ""
        # _chunk_with_padding('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
        args = [iter(iterable)] * n
        return zip_longest(*args, fillvalue=fillvalue)