// Second pass of the Union-Find labeling algorithm. Resolves // the equivalences of labels. // Modifies res by reference to avoid allocating extra memory. void SecondPass(std::map<uint, node *>& labToNode, std::vector<uint>& res, uint xLen, uint yLen, uint maxLabel) { // decide on the final labels std::map<uint, uint> equivClass; for (int i = 0; i < (int)maxLabel; ++i) { equivClass[i] = FindRep(labToNode[i]) -> label; } // second pass for (int i = 0; i < (int)yLen; ++i) { for (int j = 0; j < (int)xLen; ++j) { res[i * xLen + j] = equivClass[res[i * xLen + j]]; } } }
std::vector<int> Div(int num, int denom) { std::vector<int> digits; double fval = 1; double ival = 1; num = num * 10; std::string sDig = ""; while(digits.size() < 50 && fval != 0) { fval = modf(double(num)/double(denom),&ival); std::cout << ival << ' ' << fval << std::endl; digits.push_back(int(ival)); num = (num - (ival*denom))*10; //std::cout << Rep(digits) << std::endl; sDig = sDig + std::to_string(int(ival)); //std::cout << sDig << std::endl; if(FindRep(sDig)) { std::cout << "Rep Found" << std::endl; break; } } return digits; }
void Union(node *x, node *y) { node *xRep = FindRep(x); node *yRep = FindRep(y); yRep -> parent = xRep; }