sclass Distinguisher { new TreeMap functions; bool verbose; // function -> ranges in same order as objects Map> rangesByFunction = new TreeMap; void addFunction(S name, O f) { functions.put(name, f); } // index = class index of this object (0 or 1) // object = the object to analyze using the functions void analyze(int index, O object) { for (S fname : keys(functions)) { O f = functions.get(fname); L l = rangesByFunction.get(fname); if (l == null) rangesByFunction.put(fname, l = new L); float val = 0f; try { val = toFloat(callF(f, object)); } catch e { printShortException(e); } if (verbose) print(fname + " " + index + " => " + val); listSet(l, index, addToRange(get(l, index), val), null); } } void analyze(L objects) { for i over objects: analyze(i, objects.get(i)); } bool good() { ret quality() > 0; } L goodDiscriminators() { ret [S f in keys(rangesByFunction) | isGoodDiscriminator(f)]; } // quality = number of working discriminators int quality() { ret l(goodDiscriminators()); } bool isGoodDiscriminator(S f) { ret !rangesOverlap(rangesByFunction.get(f)); } void printStuff() { for (S key : keys(rangesByFunction)) { if (isGoodDiscriminator(key)) print("good! " + key); else print("bad: " + key); } } }