Ejemplo n.º 1
0
  @Override
  protected Bucket[] splitBucket(Bucket bucket, float xDivider, float yDivider) {
    Bucket[] newBuckets = new Bucket[4];
    for (int q = 0; q < newBuckets.length; q++) newBuckets[q] = new Bucket();

    long[] a = bucket.singles.a;
    int n = bucket.singles.n;
    for (int i = 0; i < n; i += 2) {
      long v1 = a[i];
      long v2 = a[i + 1];
      int q = quadrant(xDivider, yDivider, x(v1, v2), y(v1, v2));
      newBuckets[q].singles.append(a, i, i + 2);
    }

    Long2ObjectOpenHashMap<LongsArray> dupes = bucket.dupes;

    for (Entry<LongsArray> en : dupes.long2ObjectEntrySet()) {
      long xyKey = en.getLongKey();
      LongsArray vs = en.getValue();
      int q = quadrant(xDivider, yDivider, xFromKey(xyKey), yFromKey(xyKey));
      newBuckets[q].dupes.put(xyKey, vs);
    }

    return newBuckets;
  }
Ejemplo n.º 2
0
  protected void compactBucket(Bucket bucket) {
    LongsArray singles = bucket.singles;
    Long2ObjectOpenHashMap<LongsArray> dupes = bucket.dupes;
    long[] a = singles.a;
    int n = singles.n;

    Long2ObjectOpenHashMap<LongsArray> dupesNew = new Long2ObjectOpenHashMap<LongsArray>();
    dupesNew.defaultReturnValue(null);
    for (int i = 0; i < n; i += 2) {
      long v1 = a[i];
      long v2 = a[i + 1];
      long xyKey = xyToKey(x(v1, v2), y(v1, v2));

      LongsArray vs = dupesNew.get(xyKey);
      if (vs == null) {
        vs = new LongsArray(new long[16], 0);
        dupesNew.put(xyKey, vs);
      }
      vs.append(a, i, i + 2);
    }

    singles.n = 0;
    int dupeThreshold = 2 * max(2, (int) (0.1 * maxBucketSize));
    for (Entry<LongsArray> en : dupesNew.long2ObjectEntrySet()) {
      LongsArray vs = en.getValue();
      if (vs.n >= dupeThreshold) {
        long xyKey = en.getLongKey();
        dupes.put(xyKey, vs);
      } else {
        singles.append(vs);
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  protected void chooseDividers(
      float xMin, float xMax, float yMin, float yMax, Bucket bucket, float[] result) {
    Long2ObjectOpenHashMap<LongsArray> dupes = bucket.dupes;
    LongsArray singles = bucket.singles;
    long[] a = singles.a;
    int n = singles.n;

    double oneOverSize = 1.0 / (n / 2 + dupes.size());

    double xMean = 0;
    double yMean = 0;

    for (int i = 0; i < n; i += 2) {
      long v1 = a[i];
      long v2 = a[i + 1];
      xMean += truncInf(x(v1, v2)) * oneOverSize;
      yMean += truncInf(y(v1, v2)) * oneOverSize;
    }

    for (Entry<LongsArray> en : dupes.long2ObjectEntrySet()) {
      long xyKey = en.getLongKey();
      xMean += truncInf(xFromKey(xyKey)) * oneOverSize;
      yMean += truncInf(yFromKey(xyKey)) * oneOverSize;
    }

    result[0] = truncInf((float) xMean);
    result[1] = truncInf((float) yMean);
  }
Ejemplo n.º 4
0
  protected void compactBucket(Bucket bucket) {
    IntsArray singles = bucket.singles;
    Long2ObjectOpenHashMap<IntsArray> dupes = bucket.dupes;
    int[] a = singles.a;
    int n = singles.n;

    Long2ObjectOpenHashMap<IntsArray> dupesNew = new Long2ObjectOpenHashMap<IntsArray>();
    dupesNew.defaultReturnValue(null);
    for (int i = 0; i < n; i++) {
      int v = a[i];
      long xyKey = xyToKey(x(v), y(v));

      IntsArray vs = dupesNew.get(xyKey);
      if (vs == null) {
        vs = new IntsArray(new int[8], 0);
        dupesNew.put(xyKey, vs);
      }
      vs.append(v);
    }

    singles.n = 0;
    int dupeThreshold = max(2, (int) (0.1 * maxBucketSize));
    for (Entry<IntsArray> en : dupesNew.long2ObjectEntrySet()) {
      IntsArray vs = en.getValue();
      if (vs.n >= dupeThreshold) {
        long xyKey = en.getLongKey();
        dupes.put(xyKey, vs);
      } else {
        singles.append(vs);
      }
    }
  }