- int sib = lc;
- if (lc == index) { sib = rc; }
-
- map<string, int>::iterator itGroup;
- int pcountSize = 0;
- for (int j = 0; j < grouping.size(); j++) {
- map<string, int>::iterator itGroup = t->tree[sib].pcount.find(grouping[j]);
- if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } }
+ //while you aren't at root
+ while(t->tree[index].getParent() != -1){
+ //cout << index << endl;
+ if (m->control_pressed) { return 0; }
+
+ //am I the root for this grouping? if so I want to stop "early"
+ //does my sibling have descendants from the users groups?
+ //if so I am not the root
+ int parent = t->tree[index].getParent();
+ int lc = t->tree[parent].getLChild();
+ int rc = t->tree[parent].getRChild();
+
+ int sib = lc;
+ if (lc == index) { sib = rc; }
+
+ map<string, int>::iterator itGroup;
+ int pcountSize = 0;
+ for (int j = 0; j < grouping.size(); j++) {
+ map<string, int>::iterator itGroup = t->tree[sib].pcount.find(grouping[j]);
+ if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } }
+ }
+
+ //if yes, I am not the root
+ if (pcountSize != 0) {
+ rootForGrouping[grouping].clear();
+ rootForGrouping[grouping].insert(parent);
+ }
+
+ index = parent;