コード例 #1
0
ファイル: QuadTreeLongs2.java プロジェクト: stulegend/glimpse
  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);
      }
    }
  }
コード例 #2
0
ファイル: QuadTreeLongs2.java プロジェクト: stulegend/glimpse
  @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;
  }
コード例 #3
0
ファイル: QuadTreeInts.java プロジェクト: UW-APL-EIS/glimpse
  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);
      }
    }
  }