Exemplo n.º 1
0
  private static long test(Randomizer Randomizer, int max) {
    long started = System.currentTimeMillis();

    for (int i = 0; i < max; i++) {
      Randomizer.random();
    }
    return System.currentTimeMillis() - started;
  }
 private static long execute(Consumer<Integer> primePartitioner) {
   long fastest = Long.MAX_VALUE;
   for (int i = 0; i < 10; i++) {
     long start = System.nanoTime();
     primePartitioner.accept(1_000_000);
     long duration = (System.nanoTime() - start) / 1_000_000;
     if (duration < fastest) fastest = duration;
     System.out.println("done in " + duration);
   }
   return fastest;
 }
Exemplo n.º 3
0
 @Override
 public Array<T> appendAll(Iterable<? extends T> elements) {
   Objects.requireNonNull(elements, "elements is null");
   final Object[] source = toArray(elements);
   if (source.length == 0) {
     return this;
   } else {
     final Object[] copy = new Object[length() + source.length];
     System.arraycopy(delegate, startIndex, copy, 0, length());
     System.arraycopy(source, 0, copy, length(), source.length);
     return wrap(copy);
   }
 }
Exemplo n.º 4
0
 @Override
 public Array<T> prepend(T element) {
   final Object[] copy = new Object[length() + 1];
   copy[0] = element;
   System.arraycopy(delegate, startIndex, copy, 1, length());
   return wrap(copy);
 }
Exemplo n.º 5
0
 @Override
 public Array<T> removeAt(int index) {
   if (index < 0) {
     throw new IndexOutOfBoundsException("removeAt(" + index + ")");
   } else if (index >= length()) {
     throw new IndexOutOfBoundsException("removeAt(" + index + ")");
   } else if (index == 0) {
     return drop(1);
   } else if (index == length() - 1) {
     return dropRight(1);
   } else {
     final Object[] arr = new Object[length() - 1];
     System.arraycopy(delegate, startIndex, arr, 0, index);
     System.arraycopy(delegate, startIndex + index + 1, arr, index, length() - index - 1);
     return wrap(arr);
   }
 }
 @Override
 public long[] toArray() {
   return performOperation(
       TerminalFunctions.toArrayLongFunction(),
       false,
       (v1, v2) -> {
         long[] array = Arrays.copyOf(v1, v1.length + v2.length);
         System.arraycopy(v2, 0, array, v1.length, v2.length);
         return array;
       },
       null,
       false);
 }
Exemplo n.º 7
0
 @Override
 public Array<T> insertAll(int index, Iterable<? extends T> elements) {
   if (index < 0) {
     throw new IndexOutOfBoundsException("insert(" + index + ", e)");
   } else if (index > length()) {
     throw new IndexOutOfBoundsException(
         "insert(" + index + ", e) on Array of length " + length());
   }
   final Object[] list = toArray(elements);
   if (list.length == 0) {
     return this;
   } else {
     final Object[] copy = new Object[length() + list.length];
     if (index > 0) {
       System.arraycopy(delegate, startIndex, copy, 0, index);
     }
     System.arraycopy(list, 0, copy, index, list.length);
     if (index < length()) {
       System.arraycopy(delegate, startIndex + index, copy, index + list.length, length() - index);
     }
     return wrap(copy);
   }
 }
Exemplo n.º 8
0
 @Override
 public Array<T> slice(long beginIndex, long endIndex) {
   if (beginIndex >= endIndex || beginIndex >= length() || isEmpty()) {
     return empty();
   }
   if (beginIndex <= 0 && endIndex >= length()) {
     return this;
   }
   final int index = Math.max((int) beginIndex, 0);
   final int length = Math.min((int) endIndex, length()) - index;
   final Object[] arr = new Object[length];
   System.arraycopy(delegate, index, arr, 0, length);
   return wrap(arr);
 }
Exemplo n.º 9
0
 @Override
 protected FilterNode any(final FilterNode node0, boolean signor) {
   Objects.requireNonNull(node0);
   if (!(node0 instanceof FilterJoinNode)) {
     throw new IllegalArgumentException(
         this
             + (signor ? " or " : " and ")
             + " a node but "
             + String.valueOf(node0)
             + "is not a "
             + FilterJoinNode.class.getSimpleName());
   }
   final FilterJoinNode node = (FilterJoinNode) node0;
   if (this.nodes == null) {
     this.nodes = new FilterNode[] {node};
     this.or = signor;
     return this;
   }
   if (or == signor || this.column == null) {
     FilterNode[] newsiblings = new FilterNode[nodes.length + 1];
     System.arraycopy(nodes, 0, newsiblings, 0, nodes.length);
     newsiblings[nodes.length] = node;
     this.nodes = newsiblings;
     if (this.column == null) this.or = signor;
     return this;
   }
   this.nodes = new FilterNode[] {new FilterJoinNode(node), node};
   this.column = null;
   this.express = null;
   this.value = null;
   this.joinClass = null;
   this.joinEntity = null;
   this.joinColumns = null;
   this.or = signor;
   return this;
 }
Exemplo n.º 10
0
 public long random() {
   return System.nanoTime();
 }
Exemplo n.º 11
0
 private static long testLambda(int max) {
   return test(() -> System.nanoTime(), max);
 }