/** * Initialize an empty list. */ public BlockList() { directory = BlockList.<T> newDirectory(256); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
/** {@inheritDoc} */ @Override public boolean add(T element) { int i = tailBlkIdx; if (i < BLOCK_SIZE) { // Fast-path: Append to current tail block. tailBlock[i] = element; tailBlkIdx = i + 1; size++; return true; } // Slow path: Move to the next block, expanding if necessary. if (++tailDirIdx == directory.length) { T[][] newDir = BlockList.<T> newDirectory(directory.length << 1); System.arraycopy(directory, 0, newDir, 0, directory.length); directory = newDir; } T[] blockRef = directory[tailDirIdx]; if (blockRef == null) { blockRef = BlockList.<T> newBlock(); directory[tailDirIdx] = blockRef; } blockRef[0] = element; tailBlock = blockRef; tailBlkIdx = 1; size++; return true; }
/** * Initialize an empty list with an expected capacity. * * @param capacity * number of elements expected to be in the list. */ public BlockList(int capacity) { int dirSize = toDirectoryIndex(capacity); if ((capacity & BLOCK_MASK) != 0 || dirSize == 0) dirSize++; directory = BlockList.<T> newDirectory(dirSize); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
/** Initialize an empty list. */ public BlockList() { directory = BlockList.<T> newDirectory(256); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
/** * Initialize an empty list. */ public BlockList() { directory = BlockList.<T> newDirectory(256); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
@Override public boolean add(T element) { int i = tailBlkIdx; if (i < BLOCK_SIZE) { // Fast-path: Append to current tail block. tailBlock[i] = element; tailBlkIdx = i + 1; size++; return true; } // Slow path: Move to the next block, expanding if necessary. if (++tailDirIdx == directory.length) { T[][] newDir = BlockList.<T> newDirectory(directory.length << 1); System.arraycopy(directory, 0, newDir, 0, directory.length); directory = newDir; } T[] blockRef = directory[tailDirIdx]; if (blockRef == null) { blockRef = BlockList.<T> newBlock(); directory[tailDirIdx] = blockRef; } blockRef[0] = element; tailBlock = blockRef; tailBlkIdx = 1; size++; return true; }
/** {@inheritDoc} */ @Override public boolean add(T element) { int i = tailBlkIdx; if (i < BLOCK_SIZE) { // Fast-path: Append to current tail block. tailBlock[i] = element; tailBlkIdx = i + 1; size++; return true; } // Slow path: Move to the next block, expanding if necessary. if (++tailDirIdx == directory.length) { T[][] newDir = BlockList.<T> newDirectory(directory.length << 1); System.arraycopy(directory, 0, newDir, 0, directory.length); directory = newDir; } T[] blockRef = directory[tailDirIdx]; if (blockRef == null) { blockRef = BlockList.<T> newBlock(); directory[tailDirIdx] = blockRef; } blockRef[0] = element; tailBlock = blockRef; tailBlkIdx = 1; size++; return true; }
/** * Initialize an empty list with an expected capacity. * * @param capacity * number of elements expected to be in the list. */ public BlockList(int capacity) { int dirSize = toDirectoryIndex(capacity); if ((capacity & BLOCK_MASK) != 0 || dirSize == 0) dirSize++; directory = BlockList.<T> newDirectory(dirSize); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }
/** * Initialize an empty list with an expected capacity. * * @param capacity * number of elements expected to be in the list. */ public BlockList(int capacity) { int dirSize = toDirectoryIndex(capacity); if ((capacity & BLOCK_MASK) != 0 || dirSize == 0) dirSize++; directory = BlockList.<T> newDirectory(dirSize); directory[0] = BlockList.<T> newBlock(); tailBlock = directory[0]; }