14
14
limitations under the License.
15
15
*/
16
16
17
+ #include < meevax/kernel/box.hpp>
17
18
#include < meevax/kernel/list.hpp>
18
19
19
20
namespace meevax
20
21
{
21
22
inline namespace kernel
22
23
{
23
- struct box : public virtual pair // (value . unit)
24
- {
25
- auto unbox () -> object &
26
- {
27
- return first;
28
- }
29
-
30
- auto unbox () const -> object const &
31
- {
32
- return first;
33
- }
34
-
35
- auto set (object const & x) -> object const &
36
- {
37
- return first = x;
38
- }
39
- };
40
-
41
24
auto find (let const & b) -> object const &
42
25
{
43
- if (let x = b. as <box>(). unbox ( ); x.is <box>())
26
+ if (let & x = car (b ); x.is <box>())
44
27
{
45
- return b. as <box>(). set ( find (x) );
28
+ return x = find (x);
46
29
}
47
30
else
48
31
{
49
32
return b;
50
33
}
51
34
}
52
35
53
- /*
54
- Efficient Nondestructive Equality Checking for Trees and Graphs
55
- */
56
36
auto union_find (object const & x, object const & y, std::unordered_map<object, object> & forest)
57
37
{
58
38
using rank = std::uint32_t ;
@@ -68,16 +48,16 @@ inline namespace kernel
68
48
}
69
49
else
70
50
{
71
- if (auto rank_x = root_x. as <box>(). unbox ( ).as <rank>(),
72
- rank_y = root_y. as <box>(). unbox ( ).as <rank>(); rank_x > rank_y)
51
+ if (auto rank_x = car (root_x ).as <rank>(),
52
+ rank_y = car (root_y ).as <rank>(); rank_x > rank_y)
73
53
{
74
- root_x. as <box>(). set ( make<rank>(rank_x + rank_y) );
75
- root_y. as <box>(). set ( root_x) ;
54
+ car (root_x) = make<rank>(rank_x + rank_y);
55
+ car (root_y) = root_x;
76
56
}
77
57
else
78
58
{
79
- root_x. as <box>(). set ( root_y) ;
80
- root_y. as <box>(). set ( make<rank>(rank_x + rank_y) );
59
+ car (root_x) = root_y;
60
+ car (root_y) = make<rank>(rank_x + rank_y);
81
61
}
82
62
}
83
63
}
@@ -103,6 +83,9 @@ inline namespace kernel
103
83
return false ;
104
84
}
105
85
86
+ /*
87
+ Efficient Nondestructive Equality Checking for Trees and Graphs
88
+ */
106
89
auto equal (object const & x, object const & y, std::unordered_map<object, object> & forest) -> bool
107
90
{
108
91
return eqv (x, y) or (x.is <pair>() and
0 commit comments