+ //sort by smallest distance
+ sort(distsRight.begin(), distsRight.end(), compareSeqDist);
+ sort(distsLeft.begin(), distsLeft.end(), compareSeqDist);
+
+
+ //merge results
+ map<string, string> seen;
+ map<string, string>::iterator it;
+
+ vector<SeqDist> dists;
+ float lastRight = distsRight[0].dist;
+ float lastLeft = distsLeft[0].dist;
+
+ float maxDist = 1.0 - (minSim / 100.0);
+
+ for (int i = 0; i < numWanted+1; i++) {
+ if (m->control_pressed) { return seqsMatches; }
+
+ //add left if you havent already
+ it = seen.find(thisTemplate[distsLeft[i].index]->getName());
+ if (it == seen.end() && distsLeft[i].dist <= maxDist) {
+ dists.push_back(distsLeft[i]);
+ seen[thisTemplate[distsLeft[i].index]->getName()] = thisTemplate[distsLeft[i].index]->getName();
+ lastLeft = distsLeft[i].dist;
+// cout << "loop-left\t" << db[distsLeft[i].index]->getName() << '\t' << distsLeft[i].dist << endl;
+ }
+
+ //add right if you havent already
+ it = seen.find(thisTemplate[distsRight[i].index]->getName());
+ if (it == seen.end() && distsRight[i].dist <= maxDist) {
+ dists.push_back(distsRight[i]);
+ seen[thisTemplate[distsRight[i].index]->getName()] = thisTemplate[distsRight[i].index]->getName();
+ lastRight = distsRight[i].dist;
+// cout << "loop-right\t" << db[distsRight[i].index]->getName() << '\t' << distsRight[i].dist << endl;
+ }
+
+ if (i == numWanted) { break; }
+
+ }
+
+ //are we still above the minimum similarity cutoff
+ if ((lastLeft >= minSim) || (lastRight >= minSim)) {
+ //add in ties from left
+ int i = numWanted;
+ while (i < distsLeft.size()) {
+ if (distsLeft[i].dist == lastLeft) { dists.push_back(distsLeft[i]); }
+ else { break; }
+ i++;
+ }
+
+ //add in ties from right
+ i = numWanted;
+ while (i < distsRight.size()) {
+ if (distsRight[i].dist == lastRight) { dists.push_back(distsRight[i]); }
+ else { break; }
+ i++;
+ }
+ }