38 typename std::map<KEY, Entry>::iterator
parent_;
43 typedef typename std::map<KEY, Entry>
Map;
50 iterator it = entries_.find(key);
52 if (it == entries_.end()) {
53 it = entries_.insert(std::make_pair(key, empty)).first;
54 it->second.parent_ = it;
61 iterator
find_(
const iterator& it)
const {
63 iterator& parent = it->second.parent_;
64 if (parent != it) parent =
find_(parent);
71 return find_(initial);
75 typedef std::set<KEY>
Set;
89 iterator xRoot =
find_(x);
90 iterator yRoot =
find_(y);
91 if (xRoot == yRoot)
return;
94 if (xRoot->second.rank_ < yRoot->second.rank_)
95 xRoot->second.parent_ = yRoot;
96 else if (xRoot->second.rank_ > yRoot->second.rank_)
97 yRoot->second.parent_ = xRoot;
99 yRoot->second.parent_ = xRoot;
100 xRoot->second.rank_ = xRoot->second.rank_ + 1;
105 std::map<KEY, Set>
sets()
const {
106 std::map<KEY, Set>
sets;
107 iterator it = entries_.begin();
108 for (; it != entries_.end(); it++) {
110 sets[root->first].insert(it->first);
121 inline size_t i()
const {
return first; };
122 inline size_t j()
const {
return second; };
DSFMap< IndexPair > DSFMapIndexPair
std::map< KEY, Entry > Map
void merge(const KEY &x, const KEY &y)
Merge two sets.
KEY find(const KEY &key) const
Given key, find the representative key for the set in which it lives.
std::map< IndexPair, IndexPairSet > IndexPairSetMap
IndexPair(size_t i, size_t j)
std::set< IndexPair > IndexPairSet
const mpreal root(const mpreal &x, unsigned long int k, mp_rnd_t r=mpreal::get_default_rnd())
iterator find_(const KEY &key) const
Given key, find the root Entry.
We store the forest in an STL map, but parents are done with pointers.
IndexPairVector IndexPairSetAsArray(IndexPairSet &set)
constexpr int first(int i)
Implementation details for constexpr functions.
std::map< KEY, Entry >::iterator parent_
Small utility class for representing a wrappable pairs of ints.
iterator find__(const KEY &key) const
Given key, find iterator to initial entry.
std::vector< IndexPair > IndexPairVector
iterator find_(const iterator &it) const
Given iterator to initial entry, find the root Entry.
std::map< KEY, Set > sets() const
return all sets, i.e. a partition of all elements
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x