예제 #1
0
  public static void appendFiltered(IntsArray from, FilterInt filter, IntsModifiable to) {
    int[] a = from.a;
    int n = from.n;

    for (int i = 0; i < n; i++) {
      int v = a[i];
      if (filter.include(v)) to.append(v);
    }
  }
예제 #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 IntsModifiable 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<IntsArray> dupes = bucket.dupes;
            IntsArray singles = bucket.singles;
            int[] a = singles.a;
            int n = singles.n;

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

              for (Entry<IntsArray> en : dupes.long2ObjectEntrySet()) {
                IntsArray vs = en.getValue();
                results.append(vs);
              }
            } else if (xAll) {
              for (int i = 0; i < n; i++) {
                int v = a[i];

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

                results.append(v);
              }

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

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

                IntsArray vs = en.getValue();
                results.append(vs);
              }
            } else if (yAll) {
              for (int i = 0; i < n; i++) {
                int v = a[i];

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

                results.append(v);
              }

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

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

                IntsArray vs = en.getValue();
                results.append(vs);
              }
            } else {
              for (int i = 0; i < n; i++) {
                int v = a[i];

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

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

                results.append(v);
              }

              for (Entry<IntsArray> 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;

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

    return results.n() - nBefore;
  }