@Override public int size() { return data.size(); }
@Override public byte[] serialize(DoubleArrayList doubleArrayList) { int size = doubleArrayList.size(); byte[] bytes = new byte[Integer.BYTES + size * Double.BYTES]; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.putInt(size); double[] values = doubleArrayList.elements(); for (int i = 0; i < size; i++) { byteBuffer.putDouble(values[i]); } return bytes; }
/** * 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()); } }
@Nonnull @Override public Double extractFinalResult(@Nonnull DoubleArrayList intermediateResult) { int size = intermediateResult.size(); if (size == 0) { return DEFAULT_FINAL_RESULT; } else { double[] values = intermediateResult.elements(); Arrays.sort(values, 0, size); if (_percentile == 100) { return values[size - 1]; } else { return values[(int) ((long) size * _percentile / 100)]; } } }
/** * 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 Double value of the key */ public void put(int key, double 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); } } }
/** * 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> Returns null if the priority queue is empty. </li> * <li> Runtime complexity of O(1). </li> * </ul> * * @return Key+Value pair */ public IntDoublePair poll() { if (isEmpty()) { return null; } IntDoublePair poll = peek(); int lastIndex = _values.size() - 1; swapValues(0, lastIndex); _values.removeDouble(lastIndex); _keyToIndexMap.remove(_indexToKeyMap.get(lastIndex)); _indexToKeyMap.remove(lastIndex); if (!_values.isEmpty()) { siftDown(0); } return poll; }
int size = _values.size(); if (leftChildIndex >= size && rightChildIndex >= size) { // This is leaf node, all done. break;
private static Long2DoubleMap extractVector(Iterator<? extends Rating> ratings, IdExtractor dimension, int n) { LongArrayList ids = new LongArrayList(n > 0 ? n : LongArrayList.DEFAULT_INITIAL_CAPACITY); DoubleArrayList values = new DoubleArrayList(n > 0 ? n : DoubleArrayList.DEFAULT_INITIAL_CAPACITY); while (ratings.hasNext()) { Rating r = ratings.next(); assert ids.size() == values.size(); long id = dimension.getId(r); ids.add(id); values.add(r.getValue()); } ids.trim(); values.trim(); assert ids.elements().length == ids.size(); assert values.elements().length == values.size(); return Long2DoubleSortedArrayMap.wrapUnsorted(ids.elements(), values.elements()); }
public DocumentIteratorBuilderVisitor prepare() { curr.size( 1 ); weights.size( 0 ); weight = Double.NaN; return this; }
public DocumentIteratorBuilderVisitor prepare() { curr.size( 1 ); weights.size( 0 ); weight = Double.NaN; return this; }
public DocumentIteratorBuilderVisitor prepare() { curr.size( 1 ); weights.size( 0 ); weight = Double.NaN; return this; }
public DocumentIteratorBuilderVisitor prepare() { curr.size( 1 ); weights.size( 0 ); weight = Double.NaN; return this; }
@VisibleForTesting DoubleArrayColumnView buildDouble() { return new DoubleArrayColumnView(values.elements(), values.size()); } }
/** * Get the number of items currently in the builder. * @return The number of items in the builder. */ public int size() { assert ids.size() == scores.size(); return ids.size(); }
public Selection select(DoublePredicate predicate) { Selection bitmap = new BitmapBackedSelection(); for (int idx = 0; idx < data.size(); idx++) { double next = data.getDouble(idx); if (predicate.test(next)) { bitmap.add(idx); } } return bitmap; }
public Selection select(DoubleBiPredicate predicate, double value) { Selection bitmap = new BitmapBackedSelection(); for (int idx = 0; idx < data.size(); idx++) { double next = data.getDouble(idx); if (predicate.test(next, value)) { bitmap.add(idx); } } return bitmap; }