private void initializeHeaderOutLong() throws IOException { headerOutLong = new LongArrayList(); DataInput headerOutAsIntInput = new DataInputStream(headerOut.asInputStream()); for (int i = 0; i < numWritten; i++) { int count = headerOutAsIntInput.readInt(); headerOutLong.add(count); } }
@Override public void add(long value) { //noinspection VariableNotUsedInsideIf if (delegate != null) { throw new IllegalStateException("written out already"); } tempOut.add(value); ++numInserted; if (uniqueValues.size() <= CompressionFactory.MAX_TABLE_SIZE && !uniqueValues.containsKey(value)) { uniqueValues.put(value, uniqueValues.size()); valuesAddedInOrder.add(value); } if (value > maxVal) { maxVal = value; } if (value < minVal) { minVal = value; } }
@Override public int put(long value) { int id = _valueToIdMap.get(value); if (id == INVALID_KEY) { id = _idToValueMap.size(); _valueToIdMap.put(value, id); _idToValueMap.add(value); } return id; }
private static long[] filterLongs(LongSet longSet, long[] source) { LongList longList = new LongArrayList(); for (long value : source) { if (longSet.contains(value)) { longList.add(value); } } if (longList.size() == source.length) { return source; } else { return longList.toLongArray(); } }
public void write(@Nullable T objectToWrite) throws IOException { if (objectsSorted && prevObject != null && strategy.compare(prevObject, objectToWrite) >= 0) { objectsSorted = false; } ++numWritten; // for compatibility with the format (see GenericIndexed javadoc for description of the format), // this field is used to store nullness marker, but in a better format this info can take 1 bit. valuesOut.writeInt(objectToWrite == null ? GenericIndexed.NULL_VALUE_SIZE_MARKER : 0); if (objectToWrite != null) { strategy.writeTo(objectToWrite, valuesOut); } if (!requireMultipleFiles) { headerOut.writeInt(Ints.checkedCast(valuesOut.size())); } else { headerOutLong.add(valuesOut.size()); } if (!requireMultipleFiles && getSerializedSize() > fileSizeLimit) { requireMultipleFiles = true; initializeHeaderOutLong(); } if (objectsSorted) { prevObject = objectToWrite; } }
protected AbstractGroupCollectionAggregationState(PageBuilder pageBuilder) { this.headBlockIndex = new ShortBigArray(NULL); this.headPosition = new IntBigArray(NULL); this.nextBlockIndex = new ShortBigArray(NULL); this.nextPosition = new IntBigArray(NULL); this.tailBlockIndex = new ShortBigArray(NULL); this.tailPosition = new IntBigArray(NULL); this.currentPageBuilder = pageBuilder; this.values = new ArrayList<>(); this.sumPositions = new LongArrayList(); this.groupEntryCount = new IntBigArray(); values.add(currentPageBuilder); sumPositions.add(0L); valueBlocksRetainedSizeInBytes = 0; totalPositions = 0; capacity = 1024; nextBlockIndex.ensureCapacity(capacity); nextPosition.ensureCapacity(capacity); groupEntryCount.ensureCapacity(capacity); }
private LongList getTimers(Node<?, ?> sentinel) { LongList timers = new LongArrayList(); for (Node<?, ?> node = sentinel.getNextInVariableOrder(); node != sentinel; node = node.getNextInVariableOrder()) { timers.add(node.getVariableTime()); } return timers; }
sumPositions.add(totalPositions); currentPageBuilder = currentPageBuilder.newPageBuilderLike(); values.add(currentPageBuilder);
@Test public void testFailsWithDuplicates() { LongList keys = new LongArrayList(); keys.add(10); keys.add(42); keys.add(5); keys.add(10); try { KeyIndex idx = new FrozenHashKeyIndex(keys); fail("creating key index with duplicates should fail"); } catch (IllegalArgumentException ex) { /* expected */ } } }
@Nonnull @Override public ResultMap scoreWithDetails(long user, @Nonnull Collection<Long> items) { ResultMap results = primaryScorer.scoreWithDetails(user, items); List<Result> allResults = new ArrayList<>(items.size()); LongList toFetch = new LongArrayList(items.size() - results.size()); LongIterator iter = LongIterators.asLongIterator(items.iterator()); while (iter.hasNext()) { final long item = iter.nextLong(); Result r = results.get(item); if (r == null) { toFetch.add(item); } else { allResults.add(new FallbackResult(r, true)); } } if (!toFetch.isEmpty()) { for (Result r: baselineScorer.scoreWithDetails(user, toFetch)) { allResults.add(new FallbackResult(r, false)); } } return new BasicResultMap(allResults); }
@Test public void testAddAndPrependUpgrade() { LongList list = new CompactableLongArrayList(); long val = Integer.MAX_VALUE + 42L; list.add(42); list.add(0, val); assertThat(list.size(), equalTo(2)); assertThat(list, contains(val, 42L)); assertThat(list.get(0), equalTo(val)); assertThat(list.get(1), equalTo(42L)); }
@Override public LongList finishList() { assert size == heap.size(); int[] indices = new int[size]; // Copy backwards so the scored list is sorted. for (int i = size - 1; i >= 0; i--) { indices[i] = heap.dequeueInt(); } LongList list = new LongArrayList(size); for (int i : indices) { list.add(items.getLong(i)); } assert heap.isEmpty(); clear(); return list; }
@Test public void testSingletonNegativeLong() { LongList list = new CompactableLongArrayList(); long val = Integer.MIN_VALUE - 42L; list.add(val); assertThat(list.size(), equalTo(1)); assertThat(list.isEmpty(), equalTo(false)); assertThat(list, contains(val)); }
@Test public void testSingleton() { LongList list = new CompactableLongArrayList(); list.add(42L); assertThat(list.size(), equalTo(1)); assertThat(list.isEmpty(), equalTo(false)); assertThat(list, contains(42L)); }
@Test public void testSingletonLong() { LongList list = new CompactableLongArrayList(); long val = Integer.MAX_VALUE + 42L; list.add(val); assertThat(list.size(), equalTo(1)); assertThat(list.isEmpty(), equalTo(false)); assertThat(list, contains(val)); }
@Test public void testTwoUserSetInvasive() { LongIterator iter = new AdaptiveSparseItemIterator(context, LongUtils.packedSet(42, 39)); // this test depends on implementation details // first, get all the items from the first user (39) LongList items = new LongArrayList(); items.add(iter.nextLong()); items.add(iter.nextLong()); items.add(iter.nextLong()); items.add(iter.nextLong()); assertThat(items, containsInAnyOrder(2L, 7L, 9L, 13L)); // then check that we have next assertThat(iter.hasNext(), equalTo(true)); // again to make sure it isn't messed up assertThat(iter.hasNext(), equalTo(true)); // see if the next item is the first unique item from the second user assertThat(iter.nextLong(), equalTo(5L)); // and that's the only unique assertThat(iter.hasNext(), equalTo(false)); }