From 5141f05e6dd7a2460aced4dc0b421889e0c83938 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 17 Aug 2018 14:58:44 -0500 Subject: [PATCH] fix(union-find): keep values and representative in consistent order the merge handlers should be called with r1,r2,v1,v2 or r2,r1,v2,v1 but not a mix --- src/util/union_find.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/union_find.h b/src/util/union_find.h index 9dd0b6fbd..f8ae0402f 100644 --- a/src/util/union_find.h +++ b/src/util/union_find.h @@ -122,8 +122,10 @@ public: TRACE("union_find", tout << "merging " << r1 << " " << r2 << "\n";); if (r1 == r2) return; - if (m_size[r1] > m_size[r2]) + if (m_size[r1] > m_size[r2]) { std::swap(r1, r2); + std::swap(v1, v2); + } m_ctx.merge_eh(r2, r1, v2, v1); m_find[r1] = r2; m_size[r2] += m_size[r1];