/* Try to allocate a block from a quick list.  If the quick list contains
insufficient information, allocate space from the tail.
332959
private long allocate_from_ql(int request_size)
    throws IOException
    {
        Block block1;
        int block_size;
        int list_index;

        small_requests++;
        list_index = calculate_list_index_for_alloc(request_size);
        if (ql_heads[list_index].length > 0 ) {
            // quick list is nonempty
            block1 = ql_heads[list_index].first_block;
            ql_heads[list_index].length--;
            if (ql_heads[list_index].length == 0) {
                nonempty_lists--;
            }
            ql_heads[list_index].first_block = block1.next;

            allocated_blocks++;
            free_blocks--;
            ql_hits++;
            allocated_words += block1.size;
            free_words -= block1.size;

            // do the following as late as possible
            seek_and_count(block1.address);
            writeInt(- block1.size);

            return(block1.address + HDR_SIZE);
        } else {
            // allocate from tail
            block_size = calculate_block_size(list_index);
            return allocate_from_tail(block_size);

        }
    }
228868
def __allocateBits(self):
        
        if self._bit_count < 0:
            raise Exception( "A margin cannot request negative number of bits" )
        if self._bit_count == 0:
            return

        # Build a list of occupied ranges
        margins = self._qpart.getMargins()

        occupiedRanges = []
        for margin in margins:
            bitRange = margin.getBitRange()
            if bitRange is not None:
                # pick the right position
                added = False
                for index in range( len( occupiedRanges ) ):
                    r = occupiedRanges[ index ]
                    if bitRange[ 1 ] < r[ 0 ]:
                        occupiedRanges.insert(index, bitRange)
                        added = True
                        break
                if not added:
                    occupiedRanges.append(bitRange)

        vacant = 0
        for r in occupiedRanges:
            if r[ 0 ] - vacant >= self._bit_count:
                self._bitRange = (vacant, vacant + self._bit_count - 1)
                return
            vacant = r[ 1 ] + 1
        # Not allocated, i.e. grab the tail bits
        self._bitRange = (vacant, vacant + self._bit_count - 1)
95719
function allocate(height, length) {
	var node = new Array(length);
	node.height = height;
	if (height > 0) {
		node.sizes = new Array(length);
	}
	return node;
}
215947
public void dump_memory(Writer out)
    throws IOException
    {
        int qlist_num;

        out.write("First quick size: " + first_quick_size + "\n");
        out.write("Last quick size: " + last_quick_size + "\n");
        out.write("Grain size: " + grain_size + "\n");
        out.write("Acceptable waste: " + acceptable_waste + "\n");
        out.write("Tail pointer in memory: " + tail_ptr + "\n");
        out.write("First allocatable byte: " + start() + "\n\n");
        out.write("Free lists from memory structures\n");
        for (qlist_num = 0; qlist_num <= last_ql_index;
            qlist_num++) {
            out.write(qlist_num + ": ");
            out.write("Length = " +
                      ql_heads[qlist_num].length + "; ");
            print_memory_freelist(out, ql_heads[qlist_num].first_block);
        };
        out.write("Nonempty free lists: " + nonempty_lists + "\n");
        out.write("Tail pointer in memory: " + tail_ptr + "\n");
        out.write("First allocatable byte: " + start() + "\n\n");
    }
76432
function quickParseBlock() {
  const node = this.startNode();
  const prevPos = this.context.length - 1;

  node.body = [];

  do {
    this.next();
  } while (this.context.length > prevPos);

  this.next();
  return this.finishNode(node, "BlockStatement");
}
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;
  }
151658
boolean allocateTiny(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity) {
        return allocate(cacheForTiny(area, normCapacity), buf, reqCapacity);
    }
241063
private void init_storage_parameters()
    {
        first_quick_size_block = first_quick_size * grain_size;
        last_quick_size_block = last_quick_size * grain_size;
        last_ql_index = last_quick_size + 1 - first_quick_size;
        ql_heads = new Listhead[last_ql_index + 1];
    }
889661
public synchronized void allocate(RegularFile file, int count) throws IOException {
    int newAllocatedBlockCount = allocatedBlockCount + count;
    if (newAllocatedBlockCount > maxBlockCount) {
      throw new IOException("out of disk space");
    }

    int newBlocksNeeded = Math.max(count - blockCache.blockCount(), 0);

    for (int i = 0; i < newBlocksNeeded; i++) {
      file.addBlock(new byte[blockSize]);
    }

    if (newBlocksNeeded != count) {
      blockCache.transferBlocksTo(file, count - newBlocksNeeded);
    }

    allocatedBlockCount = newAllocatedBlockCount;
  }
131489
public synchronized NikeFS2Block allocateBlock() {
		// look for free block, i.e. first block whose index
		// bit is set to true in the allocation map.
		int freeBlockIndex = blockAllocationMap.nextSetBit(0);
		if(freeBlockIndex < 0) {
			// no free blocks left in this provider.
			return null;
		} else {
			// set index bit to false in allocation map,
			// and return in block wrapper.
			blockAllocationMap.set(freeBlockIndex, false);
			return new NikeFS2Block(this, freeBlockIndex);
		}
	}
1322426
function(block, in_tight_list) {
  var tag;
  var attr;
  var info_words;
  switch (block.t) {
    case 'Document':
      var whole_doc = this.renderBlocks(block.children);
      return (whole_doc === '' ? '' : whole_doc + '\n');
    case 'Paragraph':
      if (in_tight_list) {
        return this.renderInlines(block.inline_content);
      } else {
        return inTags('p', [], this.renderInlines(block.inline_content));
      }
      break;
    case 'BlockQuote':
      var filling = this.renderBlocks(block.children);
      return inTags('blockquote', [], filling === '' ? this.innersep :
          this.innersep + this.renderBlocks(block.children) + this.innersep);
    case 'ListItem':
      return inTags('li', [], this.renderBlocks(block.children, in_tight_list).trim());
    case 'List':
      tag = block.list_data.type == 'Bullet' ? 'ul' : 'ol';
      attr = (!block.list_data.start || block.list_data.start == 1) ?
              [] : [['start', block.list_data.start.toString()]];
      return inTags(tag, attr, this.innersep +
                    this.renderBlocks(block.children, block.tight) +
                    this.innersep);
    case 'ATXHeader':
    case 'SetextHeader':
      tag = 'h' + block.level;
      return inTags(tag, [], this.renderInlines(block.inline_content));
    case 'IndentedCode':
      return inTags('pre', [],
              inTags('code', [], this.escape(block.string_content)));
    case 'FencedCode':
      info_words = block.info.split(/ +/);
      attr = info_words.length === 0 || info_words[0].length === 0 ?
                   [] : [['class','language-' +
                                   this.escape(info_words[0],true)]];
      return inTags('pre', [],
              inTags('code', attr, this.escape(block.string_content)));
    case 'HtmlBlock':
      return block.string_content;
    case 'ReferenceDef':
      return "";
    case 'HorizontalRule':
      return inTags('hr',[],"",true);
    default:
      console.log("Uknown block type " + block.t);
      return "";
  }
}
460694
long allocate() {
        if (elemSize == 0) {
            return toHandle(0);
        }

        if (numAvail == 0 || !doNotDestroy) {
            return -1;
        }

        final int bitmapIdx = getNextAvail();
        int q = bitmapIdx >>> 6;
        int r = bitmapIdx & 63;
        assert (bitmap[q] >>> r & 1) == 0;
        bitmap[q] |= 1L << r;

        if (-- numAvail == 0) {
            removeFromPool();
        }

        return toHandle(bitmapIdx);
    }
327933
def _allocate_specified_segment(self, session, seg_id, source):
        
        try:
            with session.begin(subtransactions=True):
                alloc = (session.query(self.model).filter_by(
                    segmentation_id=seg_id).first())
                if alloc:
                    if alloc.allocated:
                        # Segment already allocated
                        return
                    else:
                        # Segment not allocated
                        count = (session.query(self.model).
                                 filter_by(allocated=False,
                                           segmentation_id=seg_id).update(
                                               {"allocated": True}))
                        if count:
                            return alloc

                # Segment to create or already allocated
                alloc = self.model(segmentation_id=seg_id,
                                   allocated=True, source=source)
                session.add(alloc)

        except db_exc.DBDuplicateEntry:
            # Segment already allocated (insert failure)
            alloc = None

        return alloc
595202
public void syncInMemorySize() throws IOException {
    if (finalizedSize == UNFINALIZED) {
      throw new IOException("Block is not finalized");
    }
    if (!inlineChecksum) {
      this.finalizedSize = blockDataFile.getFile().length();
    } else {
      this.finalizedSize = BlockInlineChecksumReader
          .getBlockSizeFromFileLength(blockDataFile.getFile().length(),
              checksumType, bytesPerChecksum);
    }
  }
201953
public int compress(int[] inBlock, int blockSize) {
                // find the best b that can lead to the smallest overall
                // compressed size
                int currentB = POSSIBLE_B[0];
                int tmpB = currentB;
                boolean hasBigNum = checkBigNumbers(inBlock, blockSize,
                        POSSIBLE_B[POSSIBLE_B.length - 1]);
                if (hasBigNum) {
                        currentB = 4;
                } else {
                        int optSize = estimateCompressedSize(inBlock,
                                blockSize, tmpB);
                        for (int i = 1; i < POSSIBLE_B.length; ++i) {
                                tmpB = POSSIBLE_B[i];
                                int curSize = estimateCompressedSize(inBlock,
                                        blockSize, tmpB);
                                if (curSize < optSize) {
                                        currentB = tmpB;
                                        optSize = curSize;
                                }
                        }
                }

                // compress the block using the above best b
                int compressedSizeInInts = compressOneBlockCore(inBlock,
                        blockSize, currentB);

                return compressedSizeInInts;
        }
1299076
boolean allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity) {
        return allocate(cacheForSmall(area, normCapacity), buf, reqCapacity);
    }
1351999
private void _recurse (@Nonnull final Block aRoot, final boolean bListMode)
  {
    Block aBlock;
    Block aList;
    Line aLine = aRoot.m_aLines;

    if (bListMode)
    {
      aRoot.removeListIndent (m_bUseExtensions);
      if (m_bUseExtensions && aRoot.m_aLines != null && aRoot.m_aLines.getLineType (m_bUseExtensions) != ELineType.CODE)
      {
        aRoot.m_sID = aRoot.m_aLines.stripID ();
      }
    }

    while (aLine != null && aLine.m_bIsEmpty)
      aLine = aLine.m_aNext;
    if (aLine == null)
      return;

    while (aLine != null)
    {
      final ELineType eType = aLine.getLineType (m_bUseExtensions);
      switch (eType)
      {
        case OTHER:
        {
          final boolean bWasEmpty = aLine.m_bPrevEmpty;
          while (aLine != null && !aLine.m_bIsEmpty)
          {
            final ELineType eType2 = aLine.getLineType (m_bUseExtensions);
            if ((bListMode || m_bUseExtensions) && (eType2 == ELineType.OLIST || eType2 == ELineType.ULIST))
              break;
            if (m_bUseExtensions &&
                (eType2 == ELineType.CODE || eType2 == ELineType.FENCED_CODE || eType2 == ELineType.PLUGIN))
              break;
            if (eType2 == ELineType.HEADLINE ||
                eType2 == ELineType.HEADLINE1 ||
                eType2 == ELineType.HEADLINE2 ||
                eType2 == ELineType.HR ||
                eType2 == ELineType.BQUOTE ||
                eType2 == ELineType.XML ||
                eType2 == ELineType.XML_COMMENT)
              break;
            aLine = aLine.m_aNext;
          }
          final EBlockType eBlockType;
          if (aLine != null && !aLine.m_bIsEmpty)
          {
            eBlockType = (bListMode && !bWasEmpty) ? EBlockType.NONE : EBlockType.PARAGRAPH;
            aRoot.split (aLine.m_aPrevious).m_eType = eBlockType;
            aRoot.removeLeadingEmptyLines ();
          }
          else
          {
            eBlockType = (bListMode && (aLine == null || !aLine.m_bIsEmpty) && !bWasEmpty) ? EBlockType.NONE
                                                                                           : EBlockType.PARAGRAPH;
            aRoot.split (aLine == null ? aRoot.m_aLineTail : aLine).m_eType = eBlockType;
            aRoot.removeLeadingEmptyLines ();
          }
          aLine = aRoot.m_aLines;
          break;
        }
        case CODE:
          while (aLine != null && (aLine.m_bIsEmpty || aLine.m_nLeading > 3))
          {
            aLine = aLine.m_aNext;
          }
          aBlock = aRoot.split (aLine != null ? aLine.m_aPrevious : aRoot.m_aLineTail);
          aBlock.m_eType = EBlockType.CODE;
          aBlock.removeSurroundingEmptyLines ();
          break;
        case XML:
        case XML_COMMENT:
          if (aLine.m_aPrevious != null)
          {
            // FIXME ... this looks wrong
            aRoot.split (aLine.m_aPrevious);
          }
          aRoot.split (aLine.m_aXmlEndLine).m_eType = eType == ELineType.XML ? EBlockType.XML : EBlockType.XML_COMMENT;
          aRoot.removeLeadingEmptyLines ();
          aLine = aRoot.m_aLines;
          break;
        case BQUOTE:
          while (aLine != null)
          {
            if (!aLine.m_bIsEmpty &&
                aLine.m_bPrevEmpty &&
                aLine.m_nLeading == 0 &&
                aLine.getLineType (m_bUseExtensions) != ELineType.BQUOTE)
              break;
            aLine = aLine.m_aNext;
          }
          aBlock = aRoot.split (aLine != null ? aLine.m_aPrevious : aRoot.m_aLineTail);
          aBlock.m_eType = EBlockType.BLOCKQUOTE;
          aBlock.removeSurroundingEmptyLines ();
          aBlock.removeBlockQuotePrefix ();
          _recurse (aBlock, false);
          aLine = aRoot.m_aLines;
          break;
        case HR:
          if (aLine.m_aPrevious != null)
          {
            // FIXME ... this looks wrong
            aRoot.split (aLine.m_aPrevious);
          }
          aRoot.split (aLine).m_eType = EBlockType.RULER;
          aRoot.removeLeadingEmptyLines ();
          aLine = aRoot.m_aLines;
          break;
        case FENCED_CODE:
          aLine = aLine.m_aNext;
          while (aLine != null)
          {
            if (aLine.getLineType (m_bUseExtensions) == ELineType.FENCED_CODE)
              break;
            // TODO ... is this really necessary? Maybe add a special
            // flag?
            aLine = aLine.m_aNext;
          }
          if (aLine != null)
            aLine = aLine.m_aNext;
          aBlock = aRoot.split (aLine != null ? aLine.m_aPrevious : aRoot.m_aLineTail);
          aBlock.m_eType = EBlockType.FENCED_CODE;
          aBlock.m_sMeta = MarkdownHelper.getMetaFromFence (aBlock.m_aLines.m_sValue);
          aBlock.m_aLines.setEmpty ();
          if (aBlock.m_aLineTail.getLineType (m_bUseExtensions) == ELineType.FENCED_CODE)
            aBlock.m_aLineTail.setEmpty ();
          aBlock.removeSurroundingEmptyLines ();
          break;
        case PLUGIN:
          aLine = aLine.m_aNext;
          while (aLine != null)
          {
            if (aLine.getLineType (m_bUseExtensions) == ELineType.PLUGIN)
              break;
            // TODO ... is this really necessary? Maybe add a special
            // flag?
            aLine = aLine.m_aNext;
          }
          if (aLine != null)
            aLine = aLine.m_aNext;
          aBlock = aRoot.split (aLine != null ? aLine.m_aPrevious : aRoot.m_aLineTail);
          aBlock.m_eType = EBlockType.PLUGIN;
          aBlock.m_sMeta = MarkdownHelper.getMetaFromFence (aBlock.m_aLines.m_sValue);
          aBlock.m_aLines.setEmpty ();
          if (aBlock.m_aLineTail.getLineType (m_bUseExtensions) == ELineType.PLUGIN)
            aBlock.m_aLineTail.setEmpty ();
          aBlock.removeSurroundingEmptyLines ();
          break;
        case HEADLINE:
        case HEADLINE1:
        case HEADLINE2:
          if (aLine.m_aPrevious != null)
            aRoot.split (aLine.m_aPrevious);
          if (eType != ELineType.HEADLINE)
            aLine.m_aNext.setEmpty ();
          aBlock = aRoot.split (aLine);
          aBlock.m_eType = EBlockType.HEADLINE;
          if (eType != ELineType.HEADLINE)
            aBlock.m_nHeadlineDepth = eType == ELineType.HEADLINE1 ? 1 : 2;
          if (m_bUseExtensions)
            aBlock.m_sID = aBlock.m_aLines.stripID ();
          aBlock.transfromHeadline ();
          aRoot.removeLeadingEmptyLines ();
          aLine = aRoot.m_aLines;
          break;
        case OLIST:
        case ULIST:
          while (aLine != null)
          {
            final ELineType eType2 = aLine.getLineType (m_bUseExtensions);
            if (!aLine.m_bIsEmpty &&
                (aLine.m_bPrevEmpty && aLine.m_nLeading == 0 && !(eType2 == ELineType.OLIST || eType2 == ELineType.ULIST)))
              break;
            aLine = aLine.m_aNext;
          }
          aList = aRoot.split (aLine != null ? aLine.m_aPrevious : aRoot.m_aLineTail);
          aList.m_eType = eType == ELineType.OLIST ? EBlockType.ORDERED_LIST : EBlockType.UNORDERED_LIST;
          aList.m_aLines.m_bPrevEmpty = false;
          aList.removeSurroundingEmptyLines ();
          aList.m_aLines.m_bPrevEmpty = false;
          _initListBlock (aList);
          aBlock = aList.m_aBlocks;
          while (aBlock != null)
          {
            _recurse (aBlock, true);
            aBlock = aBlock.m_aNext;
          }
          aList.expandListParagraphs ();
          break;
        default:
          aLine = aLine.m_aNext;
          break;
      }
    }
  }