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); } } }
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; }
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; }