Allocate a block of sequence numbers, starting from the last allocated
sequence value.

@param blockSize the number of sequences to allocate

@return allocated block of sequential numbers
961999
public SequenceGenerator.SequenceBlock allocateBlock(int blockSize) {
        final long l = this.last;
        SequenceGenerator.SequenceBlock block =
                new SequenceGenerator.SequenceBlock(l + 1, l + blockSize);
        this.last = l + blockSize;

        return block;
    }
231386
private void read_block_sizes_from_disk(boolean coalesce_blocks)
    throws IOException
    {
        long addr = FIRST_TAIL;
        int length;
        long new_tail = tail_ptr;

        while (addr < tail_ptr) {
            seek(addr);
            if (coalesce_blocks) {
                length = combine_blocks(addr);
            } else {
                length = readInt();
            }
            if (length > 0) {
                if ((length + addr >= tail_ptr) && (!readOnly)) {
                    // add last block to tail
                    new_tail = addr;
                } else {
                    add_to_freelist(addr, length);
                }
            } else {
                length = - length;
                allocated_blocks++;
                allocated_words += length;
            }
            addr = addr + length;
        }
        if ((new_tail != tail_ptr) && (!readOnly)) {
            tail_ptr = new_tail;
            seek(TAIL_DPTR);
            writeLong(tail_ptr);
        }

    }
11461
private static long getBlockSize(LocatedBlocks lbs) throws IOException {
    List<LocatedBlock> locatedBlocks = lbs.getLocatedBlocks();
    long bs = -1;
    for (LocatedBlock lb: locatedBlocks) {
      if (lb.getBlockSize() > bs) {
        bs = lb.getBlockSize();
      }
    }
    return bs;
  }
1101877
public int totalSizeInBits()
	{

		if (converted) {

			return 24 + this.countC * 3 + this.countS * blocksize_S
					+ this.countE * blocksize_E + this.countB * blocksize_B
					+ this.countL * blocksize_L + this.countT * 8;
		}

		converted = true;
		// System.out.println(this.toString());

		if (this.blocksize_B > 0) {
			this.blocksize_B = (int) Math.ceil(Math.log(blocksize_B + 1)
					/ Math.log(2.));
		}
		else if (this.countB > 0) {
			this.blocksize_B = 1;
		}

		if (this.blocksize_E > 0) {
			this.blocksize_E = (int) Math.ceil(Math.log(blocksize_E + 1)
					/ Math.log(2.));
		}
		else if (this.countE > 0) {
			this.blocksize_E = 1;
		}

		if (this.blocksize_L > 0) {
			this.blocksize_L = (int) Math.ceil(Math.log(blocksize_L + 1)
					/ Math.log(2.));
		}
		else if (this.countL > 0) {
			this.blocksize_L = 1;
		}

		if (this.blocksize_S > 0) {
			this.blocksize_S = (int) Math.ceil(Math.log(blocksize_S + 1)
					/ Math.log(2.));
		}
		else if (this.countS > 0) {
			this.blocksize_S = 1;
		}

		return 24 + this.countC * 3 + this.countS * blocksize_S + this.countE
				* blocksize_E + this.countB * blocksize_B + this.countL
				* blocksize_L + this.countT * 8;
	}
209457
public static int[] compressOneBlockOpt(final int[] inBlock,
                int blockSize) {
                // find the best b that may lead to the smallest overall
                // compressed size
                int currentB = POSSIBLE_B[0];
                int[] outBlock = null;
                int tmpB = currentB;
                // deal with the large exception cases
                boolean hasBigNum = checkBigNumbers(inBlock,
                        POSSIBLE_B[POSSIBLE_B.length - 1], blockSize);
                if (hasBigNum) {
                        currentB = 4;
                        System.out.println("has big num and the currentB is: "
                                + currentB);
                } else {
                        int optSize = estimateCompressedSize(inBlock, tmpB,
                                blockSize);
                        for (int i = 1; i < POSSIBLE_B.length; ++i) {
                                tmpB = POSSIBLE_B[i];
                                int curSize = estimateCompressedSize(inBlock,
                                        tmpB, blockSize);
                                if (curSize < optSize) {
                                        currentB = tmpB;
                                        optSize = curSize;
                                }
                        }
                }

                // compress the block using the above best b
                outBlock = compressOneBlock(inBlock, currentB, blockSize);

                return outBlock;
        }
864016
public static int simulateSerialization(List<WayDataBlock> blocks) {
        int sum = 0;
        for (WayDataBlock wayDataBlock : blocks) {
            sum += mSimulateSerialization(wayDataBlock.getOuterWay());
            if (wayDataBlock.getInnerWays() != null) {
                for (List<Integer> list : wayDataBlock.getInnerWays()) {
                    sum += mSimulateSerialization(list);
                }
            }
        }
        return sum;
    }
59471
public synchronized byte[] allocate(int minSize) {
        if (minSize <= MAX_SIZE) {
            for (int i = 0; i < SIZES.length; i++) {
                if (minSize < SIZES[i]) {
                    if (!fastBuffers.get(SIZES[i]).isEmpty()) {
                        Iterator<byte[]> interator = fastBuffers.get(SIZES[i]).iterator();
                        byte[] res = interator.next();
                        interator.remove();

                        mainFilter.remove(res);

                        if (TRACK_ALLOCATIONS) {
                            references.put(res, Thread.currentThread().getStackTrace());
                        }

                        return res;
                    }

                    return new byte[SIZES[i]];
                }
            }
        } else {
            byte[] res = null;
            for (byte[] cached : byteBuffer) {
                if (cached.length < minSize) {
                    continue;
                }
                if (res == null) {
                    res = cached;
                } else if (res.length > cached.length) {
                    res = cached;
                }
            }

            if (res != null) {
                byteBuffer.remove(res);
                mainFilter.remove(res);
                if (TRACK_ALLOCATIONS) {
                    references.put(res, Thread.currentThread().getStackTrace());
                }
                return res;
            }
        }

        return new byte[minSize];
    }
1308350
private Block allocateBlock(String src, INode[] inodes) throws IOException {
    Block b = new Block(generateBlockId(), 0, 0);
    while (isValidBlock(b)) {
      b.setBlockId(generateBlockId());
    }
    b.setGenerationStamp(getGenerationStamp());
    b = dir.addBlock(src, inodes, b);
    return b;
  }
766627
private byte[] blockForWrite(int index) throws IOException {
    if (index >= blockCount) {
      int additionalBlocksNeeded = index - blockCount + 1;
      disk.allocate(this, additionalBlocksNeeded);
    }

    return blocks[index];
  }
1221175
private static int put(byte[] block, int offset, byte[] b, int off, int len) {
    System.arraycopy(b, off, block, offset, len);
    return len;
  }
382629
public static FloatBuffer allocate (int capacity) {
        if (capacity < 0) {
            throw new IllegalArgumentException();
        }
        ByteBuffer bb = ByteBuffer.allocateDirect(capacity * 4);
        bb.order(ByteOrder.nativeOrder());
        return bb.asFloatBuffer();
    }
882448
List<List<BlockInfo>> chooseUnderReplicatedBlocks(int blocksToProcess) {
    // initialize data structure for the return value
    List<List<BlockInfo>> blocksToReplicate =
      new ArrayList<List<BlockInfo>>(UnderReplicatedBlocks.LEVEL);
    for (int i = 0; i < UnderReplicatedBlocks.LEVEL; i++) {
      blocksToReplicate.add(new ArrayList<BlockInfo>());
    }

    writeLock();
    try {
      synchronized (neededReplications) {
        if (neededReplications.size() == 0) {
          return blocksToReplicate;
        }

        for (int priority = 0; priority<UnderReplicatedBlocks.LEVEL; priority++) {
        // Go through all blocks that need replications of priority
        BlockIterator neededReplicationsIterator = neededReplications.iterator(priority);
        int numBlocks = neededReplications.size(priority);
        if (replIndex[priority] > numBlocks) {
          replIndex[priority] = 0;
        }
        // skip to the first unprocessed block, which is at replIndex
        for (int i = 0; i < replIndex[priority] && neededReplicationsIterator.hasNext(); i++) {
          neededReplicationsIterator.next();
        }
        // # of blocks to process for this priority
        int blocksToProcessIter = getQuotaForThisPriority(blocksToProcess,
            numBlocks, neededReplications.getSize(priority+1));
        blocksToProcess -= blocksToProcessIter;

        for (int blkCnt = 0; blkCnt < blocksToProcessIter; blkCnt++, replIndex[priority]++) {
          if (!neededReplicationsIterator.hasNext()) {
            // start from the beginning
            replIndex[priority] = 0;
            neededReplicationsIterator = neededReplications.iterator(priority);
            assert neededReplicationsIterator.hasNext() :
              "neededReplications should not be empty.";
          }

          BlockInfo block = neededReplicationsIterator.next();
          blocksToReplicate.get(priority).add(block);
        } // end for
        }
      } // end try
      return blocksToReplicate;
    } finally {
      writeUnlock();
    }
  }
724137
public void allocateSegments(int numberOfSegments) {
		while (getBlockCount() < numberOfSegments) {
			MemorySegment next = this.availableMemory.nextSegment();
			if (next != null) {
				this.partitionPages.add(next);
			} else {
				return;
			}
		}
	}
465098
public Allocation allocate(Mutation mutation, int size)
    {
        CommitLogSegment segment = allocatingFrom();

        Allocation alloc;
        while ( null == (alloc = segment.allocate(mutation, size)) )
        {
            // failed to allocate, so move to a new segment with enough room
            advanceAllocatingFrom(segment);
            segment = allocatingFrom;
        }

        return alloc;
    }
1286887
private static byte encodeBlockSize(int blockSize) {
    if(DEBUG_LEV > 0 )
      System.err.println("FrameHeader::encodeBlockSize : Begin");
    byte value = 0;
    int i;
    for(i = 0; i < definedBlockSizes.length; i++) {
      if(blockSize == definedBlockSizes[i]) {
        value = (byte)i;
        break;
      }
    }
    if(i >= definedBlockSizes.length) {
      if(blockSize <= 255)
        value = 0x6;
      else
        value = 0x7;
    }

    if(DEBUG_LEV > 0 )
      System.err.println("FrameHeader::encodeBlockSize : End");

    return value;
  }
196793
private static int put(byte[] block, int offset, ByteBuffer buf) {
    int len = Math.min(block.length - offset, buf.remaining());
    buf.get(block, offset, len);
    return len;
  }
1248248
public IPv6AddressSection[] mergeToSequentialBlocks(IPv6AddressSection ...sections) throws SizeMismatchException {
		List<IPAddressSegmentSeries> blocks = getMergedSequentialBlocks(this, sections, true, createSeriesCreator(getAddressCreator(), getMaxSegmentValue()));
		return blocks.toArray(new IPv6AddressSection[blocks.size()]);
	}