Skip to content

Commit 15d975a

Browse files
committed
print Min Distance State function
1 parent de4d427 commit 15d975a

1 file changed

Lines changed: 90 additions & 34 deletions

File tree

decoder.cpp

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ unsigned __int8 decoder::decode(unsigned __int8 recv) {
2121
//node* n = graphTracer(0, recv, 1);
2222
node* n = getMinDistancePaths(0, recv, 1);
2323
//printStates(n);
24+
std::cout << "\nmin dis :: " << std::bitset<8>(printStatesMinPath(n));
2425
/*for (int i = 1; n->getNextFirstStateNode() != nullptr; i++) {
2526
std::cout << "i : " << i << " | " << std::bitset<8>(n->getNextFirstStateNodeDistance()&0x03) << std::endl;
2627
std::cout << "i : " << i << " | " << std::bitset<8>(n->getNextScondStateNodeDistance() & 0x03) << std::endl;
@@ -29,6 +30,59 @@ unsigned __int8 decoder::decode(unsigned __int8 recv) {
2930
return 0;
3031
}
3132

33+
__int8 decoder::printStatesMinPath(node* n) {
34+
unsigned __int8 nextFirstStateIO = -1,
35+
nextScondStateIO = -1;
36+
37+
switch (n->getState()) {
38+
case 0:
39+
nextFirstStateIO = 0,
40+
nextScondStateIO = 3;
41+
break;
42+
case 2:
43+
nextFirstStateIO = 1,
44+
nextScondStateIO = 2;
45+
break;
46+
case 1:
47+
nextFirstStateIO = 3,
48+
nextScondStateIO = 0;
49+
break;
50+
case 3:
51+
nextFirstStateIO = 2,
52+
nextScondStateIO = 1;
53+
break;
54+
}
55+
if (n->getNextFirstStateNode() == nullptr && n->getNextScondStateNode() == nullptr) {
56+
return 0;
57+
}
58+
else if (n->getNextFirstStateNode() != nullptr && n->getNextScondStateNode() == nullptr) {
59+
//std::cout << "getNextFirstStateNode()->getState() :: " << std::bitset<8>(n->getNextFirstStateNode()->getState()) << std::endl;
60+
return this->printStatesMinPath(n->getNextFirstStateNode()) + n->getNextFirstStateNodeDistance();
61+
}
62+
else if (n->getNextScondStateNode() != nullptr && n->getNextFirstStateNode() == nullptr) {
63+
// std::cout << "getNextScondStateNode()->getState() :: " << std::bitset<8>(n->getNextScondStateNode()->getState()) << std::endl;
64+
return this->printStatesMinPath(n->getNextScondStateNode()) + n->getNextScondStateNodeDistance();
65+
}
66+
else if (n->getNextScondStateNode() != nullptr && n->getNextFirstStateNode() != nullptr) {
67+
if (n->getNextScondStateNodeDistance() > n->getNextFirstStateNodeDistance()) {
68+
return this->printStatesMinPath(n->getNextFirstStateNode()) + n->getNextFirstStateNodeDistance();
69+
}
70+
else if (n->getNextScondStateNodeDistance() < n->getNextFirstStateNodeDistance()) {
71+
return this->printStatesMinPath(n->getNextScondStateNode()) + n->getNextScondStateNodeDistance();
72+
}
73+
else {
74+
int d1 = this->printStatesMinPath(n->getNextFirstStateNode()) + n->getNextFirstStateNodeDistance();
75+
int d2 = this->printStatesMinPath(n->getNextScondStateNode()) + n->getNextScondStateNodeDistance();
76+
if (d1 > d2) {
77+
return d2;
78+
}
79+
else {
80+
return d1;
81+
}
82+
}
83+
}
84+
}
85+
3286
void decoder::printStates(node* n) {
3387
if (n->getNextFirstStateNode() == nullptr || n->getNextScondStateNode() == nullptr) {
3488
return;
@@ -80,36 +134,38 @@ node* decoder::getMinDistancePaths(unsigned __int8 state, unsigned __int8 data,
80134
case 0:
81135
nextFirstState = 0;
82136
nextFirstStateIO = 0,
83-
nextScondState = 2,
84-
nextScondStateIO = 3;
137+
nextScondState = 2,
138+
nextScondStateIO = 3;
85139
break;
86140
case 2:
87141
nextFirstState = 1;
88142
nextFirstStateIO = 1,
89-
nextScondState = 3,
90-
nextScondStateIO = 2;
143+
nextScondState = 3,
144+
nextScondStateIO = 2;
91145
break;
92146
case 1:
93147
nextFirstState = 0;
94148
nextFirstStateIO = 3,
95-
nextScondState = 2,
96-
nextScondStateIO = 0;
149+
nextScondState = 2,
150+
nextScondStateIO = 0;
97151
break;
98152
case 3:
99153
nextFirstState = 1;
100154
nextFirstStateIO = 2,
101-
nextScondState = 3,
102-
nextScondStateIO = 1;
155+
nextScondState = 3,
156+
nextScondStateIO = 1;
103157
break;
104158
}
105159
node* stateNode = new node(state & 0x03);
106160
stateNode->setNextFirstStateNodeDistance(this->hammingDistance((data >> shiftVal) & 0x03, nextFirstStateIO));
107161
stateNode->setNextScondStateNodeDistance(this->hammingDistance((data >> shiftVal) & 0x03, nextScondStateIO));
108162
if (stateNode->getNextFirstStateNodeDistance() > stateNode->getNextScondStateNodeDistance()) {
109163
stateNode->setNextScondStateNode(*this->getMinDistancePaths(nextScondState, data, level + 1));
110-
}else if (stateNode->getNextFirstStateNodeDistance() < stateNode->getNextScondStateNodeDistance()) {
164+
}
165+
else if (stateNode->getNextFirstStateNodeDistance() < stateNode->getNextScondStateNodeDistance()) {
111166
stateNode->setNextFirstStateNode(*this->getMinDistancePaths(nextFirstState, data, level + 1));
112-
}else {
167+
}
168+
else {
113169
stateNode->setNextFirstStateNode(*this->getMinDistancePaths(nextFirstState, data, level + 1));
114170
stateNode->setNextScondStateNode(*this->getMinDistancePaths(nextScondState, data, level + 1));
115171
}
@@ -124,22 +180,22 @@ node* decoder::graphTracer(unsigned __int8 state, unsigned __int8 data, unsigned
124180

125181
// data shifter : shift in each level
126182
__int8 shiftVal = 0;
127-
switch (level){
128-
case 1:
129-
shiftVal = 6;
130-
break;
131-
case 2:
132-
shiftVal = 4;
133-
break;
134-
case 3:
135-
shiftVal = 2;
136-
break;
137-
case 4:
138-
shiftVal = 0;
139-
break;
140-
default:
141-
shiftVal = 0;
142-
break;
183+
switch (level) {
184+
case 1:
185+
shiftVal = 6;
186+
break;
187+
case 2:
188+
shiftVal = 4;
189+
break;
190+
case 3:
191+
shiftVal = 2;
192+
break;
193+
case 4:
194+
shiftVal = 0;
195+
break;
196+
default:
197+
shiftVal = 0;
198+
break;
143199
}
144200

145201

@@ -154,26 +210,26 @@ node* decoder::graphTracer(unsigned __int8 state, unsigned __int8 data, unsigned
154210
case 0:
155211
nextFirstState = 0;
156212
nextFirstStateIO = 0,
157-
nextScondState = 2,
158-
nextScondStateIO = 3;
213+
nextScondState = 2,
214+
nextScondStateIO = 3;
159215
break;
160216
case 2:
161217
nextFirstState = 1;
162218
nextFirstStateIO = 1,
163-
nextScondState = 3,
164-
nextScondStateIO = 2;
219+
nextScondState = 3,
220+
nextScondStateIO = 2;
165221
break;
166222
case 1:
167223
nextFirstState = 0;
168224
nextFirstStateIO = 3,
169-
nextScondState = 2,
170-
nextScondStateIO = 0;
225+
nextScondState = 2,
226+
nextScondStateIO = 0;
171227
break;
172228
case 3:
173229
nextFirstState = 1;
174230
nextFirstStateIO = 2,
175-
nextScondState = 3,
176-
nextScondStateIO = 1;
231+
nextScondState = 3,
232+
nextScondStateIO = 1;
177233
break;
178234
}
179235
node* stateNode = new node(state & 0x03);

0 commit comments

Comments
 (0)