public LongSortedAction() { super(s -> s.sorted(), LongStream.class, SORTED); }
public static long[] getReplicationBarriers(Result result) { return result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER) .stream().mapToLong(MetaTableAccessor::getReplicationBarrier).sorted().distinct().toArray(); }
@Override public LongStream sorted() { return wrap(stream().sorted()); }
@Override @SuppressWarnings("unchecked") public TS build(boolean parallel) { final TS built = previous().build(parallel); if (built instanceof Stream<?>) { if (comparator == null) { return (TS) ((Stream<T>) built).sorted(); } else { return (TS) ((Stream<T>) built).sorted(comparator); } } else if (built instanceof IntStream) { return (TS) ((IntStream) built).sorted(); } else if (built instanceof LongStream) { return (TS) ((LongStream) built).sorted(); } else if (built instanceof DoubleStream) { return (TS) ((DoubleStream) built).sorted(); } else { throw new UnsupportedOperationException( "Built stream did not match any known stream interface." ); } } }
private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs) { // aggregate level assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueLongs(maxError, inputs)); // test scalars List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList()); SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page); assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99); }
@Test void shouldDeduplicateWithRandomArrays() { int arrayLength = 5000; int iterations = 10; for ( int i = 0; i < iterations; i++ ) { long[] array = ThreadLocalRandom.current().longs( arrayLength, 0, arrayLength ).sorted().toArray(); long[] dedupedActual = PrimitiveLongCollections.deduplicate( array ); TreeSet<Long> set = new TreeSet<>(); for ( long value : array ) { set.add( value ); } long[] dedupedExpected = new long[set.size()]; Iterator<Long> itr = set.iterator(); for ( int j = 0; j < dedupedExpected.length; j++ ) { assertTrue( itr.hasNext() ); dedupedExpected[j] = itr.next(); } assertArrayEquals( dedupedExpected, dedupedActual ); } }
public static long[] getReplicationBarriers(Result result) { return result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER) .stream().mapToLong(MetaTableAccessor::getReplicationBarrier).sorted().distinct().toArray(); }
public LongSortedAction() { super(s -> s.sorted(), LongStream.class, SORTED); }
@Override public ExLongStream sorted() { return ExLongStream.of(stream.sorted()); }
@Override public LongStream sorted() { return new LongResourceStream(stream.sorted(), closeOnTerminalOperation, resources); }
@Override public long getOldestCheckpointCreationTimestamp() { return StreamSupport.stream(store.checkpoints().spliterator(), false) .map(store::allCheckpointInfo) .map(i -> i.get(CHECKPOINT_METADATA + "created")) .mapToLong(l -> l == null ? 0 : Long.valueOf(l)) .sorted() .findFirst() .orElse(0); }
public long firstTransactionTimestamp() { return entries.stream() .mapToLong(e -> Long.parseLong(e[TRANSACTION_TIMESTAMP.getColumn()])) .sorted() .limit(1) .findFirst() .getAsLong(); }
@Override public LongStreamEx sorted() { return new LongStreamEx(stream().sorted(), context); }
@Override public LongStream sorted() { return wrap(stream().sorted()); }
/** * Shuffle int stream. * * @param stream the stream * @return the int stream */ public static IntStream shuffle(@Nonnull IntStream stream) { // http://primes.utm.edu/lists/small/10000.txt long coprimeA = 41387; long coprimeB = 9967; long ringSize = coprimeA * coprimeB - 1; @Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize; @Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize); @Nonnull IntUnaryOperator conditions = x -> { assert x < ringSize; assert x >= 0; return x; }; return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv); }
/** * Shuffle int stream. * * @param stream the stream * @return the int stream */ public static IntStream shuffle(@Nonnull IntStream stream) { // http://primes.utm.edu/lists/small/10000.txt long coprimeA = 41387; long coprimeB = 9967; long ringSize = coprimeA * coprimeB - 1; @Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize; @Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize); @Nonnull IntUnaryOperator conditions = x -> { assert x < ringSize; assert x >= 0; return x; }; return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv); }
/** * Returns a stream consisting of the elements of this stream in reverse * sorted order. The elements are compared for equality according to * {@link java.lang.Double#compare(double, double)}. * * <p> * This is a stateful intermediate operation. * * @return the new stream * @since 0.0.8 */ public DoubleStreamEx reverseSorted() { return new DoubleStreamEx(stream().mapToLong(d -> { long l = Double.doubleToRawLongBits(d); return l ^ (((l >>> 63) - 1) | Long.MIN_VALUE); }).sorted().mapToDouble(l -> Double.longBitsToDouble(l ^ ((-(l >>> 63)) | Long.MIN_VALUE))), context); }
/** * Returns a stream consisting of the elements of this stream in reverse * sorted order. * * <p> * This is a stateful intermediate operation. * * @return the new stream * @since 0.0.8 */ public LongStreamEx reverseSorted() { LongUnaryOperator inv = x -> ~x; return new LongStreamEx(stream().map(inv).sorted().map(inv), context); }
private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs) { // aggregate level assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueLongs(maxError, inputs)); // test scalars List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList()); SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page); assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99); }
private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs) { // aggregate level assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueLongs(maxError, inputs)); // test scalars List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList()); SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page); assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99); }