Exemple #1
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);
      }
    }
  }
Exemple #2
0
  public void remove(int v) {
    float x = x(v);
    float y = y(v);
    Bucket bucket = leaf(x, y).bucket;

    // The default return value for bucket.dupes is set to bucket.singles.
    // See note in add() for the reasoning behind this confusing choice.
    //
    long xyKey = xyToKey(x, y);
    IntsArray vs = bucket.dupes.get(xyKey);
    vs.remove(v);
    if (vs != bucket.singles && vs.n == 0) bucket.dupes.remove(xyKey);
  }
Exemple #3
0
  public static Map<String, IntsArray> partitionUnique(String[] data) {
    Map<String, IntsArray> unique = new LinkedHashMap<String, IntsArray>();

    for (int i = 0; i < data.length; i++) {
      String s = data[i];
      if (s != null) {
        IntsArray index = unique.get(s);
        if (index == null) {
          index = new IntsArray();
          unique.put(s, index);
        }

        index.append(i);
      }
    }

    return unique;
  }
Exemple #4
0
  public static Map<Strings, IntsArray> partitionUnique(String[]... data) {
    Map<Strings, IntsArray> unique = new LinkedHashMap<Strings, IntsArray>();

    int nfields = data.length;
    int size = data[0].length;

    Strings s = new Strings(nfields);
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < nfields; j++) s.strings[j] = data[j][i];

      IntsArray index = unique.get(s);
      if (index == null) {
        index = new IntsArray();
        unique.put(s.copy(), index);
      }

      index.append(i);
    }

    return unique;
  }