/** * Returns true if the node at specified index has children, false otherwise. * Just checking for existence of left child is sufficient (array backed heap). * * @param index Index to check * @return True if node has children, false otherwise. */ private boolean hasChildren(int index) { return (getLeftChildIndex(index) < _values.size()); } }
@Override protected Page computeNext() { if (pageCounter == channels[0].size()) { return endOfData(); } Block[] blocks = Stream.of(channels) .map(channel -> channel.get(pageCounter)) .toArray(Block[]::new); pageCounter++; return new Page(blocks); } };
public void compact() { if (eagerCompact) { return; } for (int channel = 0; channel < types.size(); channel++) { ObjectArrayList<Block> blocks = channels[channel]; for (int i = nextBlockToCompact; i < blocks.size(); i++) { Block block = blocks.get(i); // Copy the block to compact its size Block compactedBlock = block.copyRegion(0, block.getPositionCount()); blocks.set(i, compactedBlock); pagesMemorySize -= block.getRetainedSizeInBytes(); pagesMemorySize += compactedBlock.getRetainedSizeInBytes(); } } nextBlockToCompact = channels[0].size(); estimatedSize = calculateEstimatedSize(); }
int pageIndex = channelBuilders.get(0).size() - 1; int pagePosition = currentPageBuilder.getPositionCount() - 1; long address = encodeSyntheticAddress(pageIndex, pagePosition);
/** * Returns the key+value pair with the max priority (min for minHeap mode) * <ul> * <li> key+value pair is removed from the priority queue. </li> * <li> Throws runtime exception if the priority queue is empty. </li> * <li> Runtime complexity of O(1). </li> * </ul> * * @return Key+Value pair */ public IntObjectPair<T> poll() { if (isEmpty()) { throw new RuntimeException("Empty collection, nothing to remove"); } else { IntObjectPair<T> poll = peek(); int lastIndex = _values.size() - 1; swapValues(0, lastIndex); _values.remove(lastIndex); _keyToIndexMap.remove(_indexToKeyMap.get(lastIndex)); _indexToKeyMap.remove(lastIndex); if (!_values.isEmpty()) { siftDown(0); } return poll; } }
public void addPage(Page page) { // ignore empty pages if (page.getPositionCount() == 0) { return; } positionCount += page.getPositionCount(); int pageIndex = (channels.length > 0) ? channels[0].size() : 0; for (int i = 0; i < channels.length; i++) { Block block = page.getBlock(i); if (eagerCompact) { block = block.copyRegion(0, block.getPositionCount()); } channels[i].add(block); pagesMemorySize += block.getRetainedSizeInBytes(); } for (int position = 0; position < page.getPositionCount(); position++) { long sliceAddress = encodeSyntheticAddress(pageIndex, position); valueAddresses.add(sliceAddress); } estimatedSize = calculateEstimatedSize(); }
/** * Puts the element into the priority queue. * <ul> * <li> If key does not exist, it is added to the priority queue. </li> * <li> If key exists, then the value is updated, and the priority queue ordering is maintained. </li> * <li> Runtime complexity of {@code O(log(n)}). </li> * </ul> * @param key Integer key for the value * @param value Value of the key */ @SuppressWarnings("unchecked") public void put(int key, T value) { if (!_keyToIndexMap.containsKey(key)) { _values.add(value); int last = _values.size() - 1; updateKeyIndexMap(key, last); siftUp(last); } else { int index = _keyToIndexMap.get(key); _values.set(index, value); // Sift the value up or down, as the case may be. if (!siftDown(index)) { siftUp(index); } } }
int size = _values.size(); if (leftChildIndex >= size && rightChildIndex >= size) { // This is leaf node, all done. break;
@Override public synchronized void writeRow(List<?> row) throws IOException { checkRowWidth(row.size()); // Add the data to the row assert rowData.size() == fixedColumns; rowData.addAll(row); try { // write the row baseWriter.writeRow(rowData); } finally { // reset the row rowData.removeElements(fixedColumns, rowData.size()); } }
/** * Construct a new prefixed table writer. * * @param writer The underlying table writer to write to. This writer is <b>not</b> closed * when the prefixed writer is closed. * @param values The initial values to write. Each row written to this table * writer is written to the base writer with these values prefixed. */ public PrefixedTableWriter(TableWriter writer, List<?> values) { baseWriter = writer; TableLayout baseLayout = writer.getLayout(); if (values.size() > baseLayout.getColumnCount()) { throw new IllegalArgumentException("Value array too wide"); } rowData = new ObjectArrayList<>(writer.getLayout().getColumnCount()); rowData.addAll(values); fixedColumns = values.size(); TableLayoutBuilder bld = new TableLayoutBuilder(); List<String> bheaders = baseLayout.getColumns(); for (String h : bheaders.subList(fixedColumns, bheaders.size())) { bld.addColumn(h); } layout = bld.build(); assert layout.getColumnCount() + rowData.size() == writer.getLayout().getColumnCount(); }
/** Checks whether there are more blocks. * * @return true if we there are more blocks. */ public boolean hasMoreBlocks() { return currentBlock < blocks.size() - 1; }
@Override public int getNumberOfInstances() { return this.instanceList.size(); }
/** Returns the number of callbacks in this builder. * * @return the number of callbacks in this composer. */ public int size() { return callbacks.size(); }
/** Checks whether there are more blocks. * * @return true if we there are more blocks. */ public boolean hasMoreBlocks() { return currentBlock < blocks.size() - 1; }
/** Returns the number of callbacks in this builder. * * @return the number of callbacks in this composer. */ public int size() { return callbacks.size(); }
private ComposedCallback( final ObjectArrayList<Callback> callbacks ) { super(); this.callbacks = callbacks; this.size = callbacks.size(); this.cont = new boolean[ size ]; this.callback = new Callback[ size ]; this.callbacks.toArray( callback ); }
public DocumentIteratorBuilderVisitor prepare() { curr.size( 1 ); weights.size( 0 ); weight = Double.NaN; return this; }
@Override public boolean add(final T element) { if (this.usedElements == super.size()) // append super.add(element); else super.set(this.usedElements, element); this.usedElements++; return true; }
public Interval nextInterval() throws IOException { if ( pos < cachedIntervals.size() ) return cachedIntervals.get( pos++ ); else { final Interval next = intervalIterator.nextInterval(); if ( next == null ) return null; cachedIntervals.add( next ); pos++; return next; } }
@Override protected Class<?>[] getSignatureTypes(final Method method) { Class<?>[] signatureTypes = super.getSignatureTypes(method); if (this.needsInstance(method)) { final ObjectArrayList<Class<?>> paramList = ObjectArrayList.wrap(signatureTypes); paramList.ensureCapacity(paramList.size() + 1); paramList.add(0, method.getDeclaringClass()); signatureTypes = paramList.elements(); } return signatureTypes; }