5 #ifndef HOBBES_UTIL_UNIONFIND_HPP_INCLUDED 6 #define HOBBES_UTIL_UNIONFIND_HPP_INCLUDED 8 #include <unordered_map> 15 template <
typename K,
typename V>
27 template <
typename K,
typename V,
typename KVLift,
typename VPlus>
40 return findNode(k)->value;
44 void join(
const K& k0,
const K& k1) {
45 node_t* lhs = findNode(k0);
46 node_t* rhs = findNode(k1);
54 }
else if (lhs == rhs) {
69 size_t c = this->eqsz;
72 for (
const auto& kn : rhs.
nodes) {
73 if (this->nodes.find(kn.first) == this->nodes.end()) {
79 for (
const auto& kn : rhs.
nodes) {
80 node_t* rrep = findRepresentative(kn.second.get());
81 if (kn.first != rrep->
key) {
82 join(kn.first, rrep->
key);
86 return this->eqsz - c;
92 vs.reserve(nodes.size());
93 for (
const auto& kn : this->nodes) {
94 vs.push_back(kn.first);
102 typedef std::unique_ptr<node_t>
nodep;
114 typename nodes_t::const_iterator n = this->nodes.find(k);
116 if (n != this->nodes.end()) {
117 return findRepresentative(n->second.get());
120 this->nodes[k] = nodep(n);
std::unique_ptr< node_t > nodep
Definition: unionfind.H:102
void join(const K &k0, const K &k1)
Definition: unionfind.H:44
V value
Definition: unionfind.H:22
size_t merge(const equivalence_mapping< K, V, KVLift, VPlus > &rhs)
Definition: unionfind.H:67
std::vector< K > values() const
Definition: unionfind.H:90
size_t size() const
Definition: unionfind.H:34
void apply(const transition_lookahead &tl, parserdef *p)
Definition: lalr.C:564
eqsetmem< K, V > node_t
Definition: unionfind.H:101
size_t eqsz
Definition: unionfind.H:99
node_t * findNode(const K &k)
Definition: unionfind.H:113
V & find(const K &k)
Definition: unionfind.H:39
Definition: unionfind.H:16
Definition: unionfind.H:28
eqsetmem< K, V > * representative
Definition: unionfind.H:24
K key
Definition: unionfind.H:21
eqsetmem(const K &key, const V &value)
Definition: unionfind.H:17
equivalence_mapping()
Definition: unionfind.H:30
std::unordered_map< K, nodep > nodes_t
Definition: unionfind.H:103
nodes_t nodes
Definition: unionfind.H:104
static node_t * findRepresentative(node_t *n)
Definition: unionfind.H:106
size_t rank
Definition: unionfind.H:23