void setBestAncestor(int i, Ancestor bestAnc) { int left = nodes[i].leftSon, right = nodes[i].rightSon; if (getMaxDist(bestAnc) >= getMaxDist(i)) bestAncestors[i] = bestAnc; if (left != -1) { if (getMaxDist(bestAnc) < rightDepth[i]) setBestAncestor(left, makeAncestor(i, 1, 2)); else setBestAncestor(left, makeAncestor(bestAnc.node, bestAnc.dist + 1, bestAnc.whereToGo)); } if (right != -1) { if (getMaxDist(bestAnc) < leftDepth[i]) setBestAncestor(right, makeAncestor(i, 1, 1)); else setBestAncestor(right, makeAncestor(bestAnc.node, bestAnc.dist + 1, bestAnc.whereToGo)); } }
bool RecDistList::addRec(int dist, Record *record, chromDirType chromDir) { int newPos = 0; bool mustAppend = false; int useElemIdx = 0; if (dist > getMaxDist()) { //dist is bigger than any currently contained. if (_currNumIdxs == _kVal) { //already full with smaller distances return false; } mustAppend = true; useElemIdx = _currNumIdxs; newPos = _currNumIdxs; } if (find(dist, newPos)) { _allRecs[_distIndex[newPos].second]->push_back(elemPairType(chromDir, record)); _totalRecs++; return true; } if (!mustAppend) { //smaller than maxDist, and doesn't currently exist. must insert //newPos now is the insertion point. int startShiftPos = 0; if (_currNumIdxs == _kVal) { //already full. must remove oldest max. //determine which vector it was using //so we can re-use it. startShiftPos = _kVal-1; useElemIdx = _distIndex[startShiftPos].second; } else { //can add a new element startShiftPos = _currNumIdxs; useElemIdx = _currNumIdxs; _currNumIdxs++; } for (int i=startShiftPos; i > newPos; i--) { _distIndex[i].first = _distIndex[i-1].first; _distIndex[i].second = _distIndex[i-1].second; } } else { _currNumIdxs++; } _allRecs[useElemIdx]->clear(); _allRecs[useElemIdx]->reserve(16); _allRecs[useElemIdx]->push_back(elemPairType(chromDir, record)); _distIndex[newPos].first = dist; _distIndex[newPos].second = useElemIdx; _empty = false; _totalRecs++; return true; }
int getMaxDist(int i) { return getMaxDist(bestAncestors[i]); }