sclass ImageBuckets { float similarityThreshold = 0.99f; new LL buckets; new Map duplicates; int images; void addImage(RGBImage img) { new Best best; for i over buckets: { Pair p = rgbMostSimilarImage(pat, buckets.get(i), 0); best.put(i, p.b); if (p.b == 1) { // it's a duplicate ++images; duplicates.set(i, toInt(duplicates.get(i))+1); ret; } } ++images; if (best.score() < minScore) buckets.add(ll(pat)); // new bucket else buckets.get(best!).add(pat); } }