Exemplo n.º 1
0
  public static void appendFiltered(LongsArray from, FilterLong2 filter, LongsModifiable to) {
    long[] a = from.a;
    int n = from.n;

    for (int i = 0; i < n; i += 2) {
      long v1 = a[i];
      long v2 = a[i + 1];
      if (filter.include(v1, v2)) to.append(a, i, i + 2);
    }
  }
Exemplo n.º 2
0
  /** @return The number of elements appended to {@code results}. */
  public int search(
      final float xMin,
      final float xMax,
      final float yMin,
      final float yMax,
      final LongsModifiable results) {
    int nBefore = results.n();

    accumulate(
        xMin,
        xMax,
        yMin,
        yMax,
        new Accumulator<Bucket>() {
          public void accumulate(
              Bucket bucket,
              float xMinBucket,
              float xMaxBucket,
              float yMinBucket,
              float yMaxBucket) {
            boolean xAll = (xMin <= xMinBucket && xMaxBucket <= xMax);
            boolean yAll = (yMin <= yMinBucket && yMaxBucket <= yMax);
            Long2ObjectOpenHashMap<LongsArray> dupes = bucket.dupes;
            LongsArray singles = bucket.singles;
            long[] a = singles.a;
            int n = singles.n;

            if (xAll && yAll) {
              results.append(singles);

              for (Entry<LongsArray> en : dupes.long2ObjectEntrySet()) {
                LongsArray vs = en.getValue();
                results.append(vs);
              }
            } else if (xAll) {
              for (int i = 0; i < n; i += 2) {
                long v1 = a[i];
                long v2 = a[i + 1];

                float y = y(v1, v2);
                if (y < yMin || y > yMax) continue;

                results.append(a, i, i + 2);
              }

              for (Entry<LongsArray> en : dupes.long2ObjectEntrySet()) {
                long xyKey = en.getLongKey();

                float y = yFromKey(xyKey);
                if (y < yMin || y > yMax) continue;

                LongsArray vs = en.getValue();
                results.append(vs);
              }
            } else if (yAll) {
              for (int i = 0; i < n; i += 2) {
                long v1 = a[i];
                long v2 = a[i + 1];

                float x = x(v1, v2);
                if (x < xMin || x > xMax) continue;

                results.append(a, i, i + 2);
              }

              for (Entry<LongsArray> en : dupes.long2ObjectEntrySet()) {
                long xyKey = en.getLongKey();

                float x = xFromKey(xyKey);
                if (x < xMin || x > xMax) continue;

                LongsArray vs = en.getValue();
                results.append(vs);
              }
            } else {
              for (int i = 0; i < n; i += 2) {
                long v1 = a[i];
                long v2 = a[i + 1];

                float x = x(v1, v2);
                if (x < xMin || x > xMax) continue;

                float y = y(v1, v2);
                if (y < yMin || y > yMax) continue;

                results.append(a, i, i + 2);
              }

              for (Entry<LongsArray> en : dupes.long2ObjectEntrySet()) {
                long xyKey = en.getLongKey();

                float x = xFromKey(xyKey);
                if (x < xMin || x > xMax) continue;

                float y = yFromKey(xyKey);
                if (y < yMin || y > yMax) continue;

                LongsArray vs = en.getValue();
                results.append(vs);
              }
            }
          }
        });

    return (results.n() - nBefore) / 2;
  }