/**
  * Creates a new front-coded list containing the arrays returned by the given iterator.
  *
  * @param arrays an iterator returning arrays.
  * @param ratio the desired ratio.
  */
 public CharArrayFrontCodedList(final Iterator<char[]> arrays, final int ratio) {
   if (ratio < 1) throw new IllegalArgumentException("Illegal ratio (" + ratio + ")");
   char[][] array = CharBigArrays.EMPTY_BIG_ARRAY;
   long[] p = LongArrays.EMPTY_ARRAY;
   char[][] a = new char[2][];
   long curSize = 0;
   int n = 0, b = 0, common, length, minLength;
   while (arrays.hasNext()) {
     a[b] = arrays.next();
     length = a[b].length;
     if (n % ratio == 0) {
       p = LongArrays.grow(p, n / ratio + 1);
       p[n / ratio] = curSize;
       array = CharBigArrays.grow(array, curSize + count(length) + length, curSize);
       curSize += writeInt(array, length, curSize);
       CharBigArrays.copyToBig(a[b], 0, array, curSize, length);
       curSize += length;
     } else {
       minLength = a[1 - b].length;
       if (length < minLength) minLength = length;
       for (common = 0; common < minLength; common++) if (a[0][common] != a[1][common]) break;
       length -= common;
       array =
           CharBigArrays.grow(array, curSize + count(length) + count(common) + length, curSize);
       curSize += writeInt(array, length, curSize);
       curSize += writeInt(array, common, curSize);
       CharBigArrays.copyToBig(a[b], common, array, curSize, length);
       curSize += length;
     }
     b = 1 - b;
     n++;
   }
   this.n = n;
   this.ratio = ratio;
   this.array = CharBigArrays.trim(array, curSize);
   this.p = LongArrays.trim(p, (n + ratio - 1) / ratio);
 }
Beispiel #2
0
  /**
   * Get the keys of this vector sorted by the value of the items stored for each key.
   *
   * @param decreasing If {@code true}, sort in decreasing order.
   * @return The sorted list of keys of this vector.
   */
  public LongArrayList keysByValue(boolean decreasing) {
    long[] skeys = keySet().toLongArray();

    LongComparator cmp;
    // Set up the comparator. We use the key as a secondary comparison to get
    // a reproducible sort irrespective of sorting algorithm.
    if (decreasing) {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k2), get(k1));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    } else {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k1), get(k2));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    }

    LongArrays.quickSort(skeys, cmp);
    return LongArrayList.wrap(skeys);
  }
Beispiel #3
0
 public boolean equals(final long[] a, final long[] b) {
   return LongArrays.equals(a, b);
 }
Beispiel #4
0
 /**
  * Creates a new tree set and fills it with the elements of a given array using a given {@link
  * Comparator}.
  *
  * @param a an array whose elements will be used to fill the set.
  * @param offset the first element to use.
  * @param length the number of elements to use.
  * @param c a {@link Comparator} (even better, a type-specific comparator).
  */
 public LongAVLTreeSet(
     final long[] a, final int offset, final int length, final Comparator<? super Long> c) {
   this(c);
   LongArrays.ensureOffsetLength(a, offset, length);
   for (int i = 0; i < length; i++) add(a[offset + i]);
 }
Beispiel #5
0
 /** Clears this filter. */
 public void clear() {
   LongArrays.fill(bits, 0);
   size = 0;
 }