sclass ImageBuckets { float similarityThreshold = 0.99f; new LL buckets; new Map duplicates; int images, totalDuplicates; void addImage(RGBImage pat) { 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; ++totalDuplicates; duplicates.put(i, toInt(duplicates.get(i))+1); ret; } } ++images; if (best.score() < similarityThreshold) buckets.add(ll(pat)); // new bucket else buckets.get(best!).add(pat); } }