-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
117 lines (103 loc) · 2.96 KB
/
complex.cpp
File metadata and controls
117 lines (103 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "complex.h"
complex_t::complex_t() {}
/*
equals
Hash- and order-based equality operator.
*/
const bool equals(const complex_t* const lhs, const complex_t* const rhs)
{
if (lhs && rhs) // If both complexes exist...
{
const complex_t* const lhs_inner_rest = lhs->get_inner_rest();
const complex_t* const rhs_inner_rest = rhs->get_inner_rest();
const complex_t* const lhs_rest = lhs->get_rest();
const complex_t* const rhs_rest = rhs->get_rest();
if (lhs_rest && rhs_rest) // If both complexes continue on the top level...
{
if (lhs_inner_rest && rhs_inner_rest) // If both complexes have a level down and continue on the top level...
{
const bool o = lhs->get_first_hash() == rhs->get_first_hash() && equals(lhs_inner_rest, rhs_inner_rest) && equals(lhs_rest, rhs_rest);
delete lhs_inner_rest;
delete rhs_inner_rest;
delete lhs_rest;
delete rhs_rest;
return o;
}
else if ((bool)lhs_inner_rest != (bool)rhs_inner_rest) // If one of the complexes has a level down and not the other and both continue on the top level...
{
if (lhs_inner_rest)
{
delete lhs_inner_rest;
}
if (rhs_inner_rest)
{
delete rhs_inner_rest;
}
delete lhs_rest;
delete rhs_rest;
return false;
}
else // If both complexes don't have a level down but do continue on the top level...
{
const bool o = lhs->get_first_hash() == rhs->get_first_hash() && equals(lhs_rest, rhs_rest);
delete lhs_rest;
delete rhs_rest;
return o;
}
}
else if ((bool)lhs_rest != (bool)rhs_rest) // If one of the complexes continues on the top level and not the other...
{
if (lhs_inner_rest)
{
delete lhs_inner_rest;
}
if (rhs_inner_rest)
{
delete rhs_inner_rest;
}
if (lhs_rest)
{
delete lhs_rest;
}
if (rhs_rest)
{
delete rhs_rest;
}
return false;
}
else // If both complexes don't continue on the top level...
{
if (lhs_inner_rest && rhs_inner_rest) // If both complexes have a level down and neither continues on the top level...
{
const bool o = lhs->get_first_hash() == rhs->get_first_hash() && equals(lhs_inner_rest, rhs_inner_rest);
delete lhs_inner_rest;
delete rhs_inner_rest;
return o;
}
else if ((bool)lhs_inner_rest != (bool)rhs_inner_rest) // If one of the complexes has a level down and not the other and neither continues on the top level...
{
if (lhs_inner_rest)
{
delete lhs_inner_rest;
}
if (rhs_inner_rest)
{
delete rhs_inner_rest;
}
return false;
}
else // If both complexes don't have a level down nor continue on the top level...
{
return lhs->get_first_hash() == rhs->get_first_hash();
}
}
}
else if (!lhs && !rhs) // If neither complex exists...
{
return true;
}
else // If one complex exists but not the other...
{
return false;
}
}