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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#include "multaln.h"
#define TRACE 0
static char XlatEdgeType(char c)
{
if ('E' == c)
return 'D';
if ('J' == c)
return 'I';
return c;
}
static const char *BitsToStr(char Bits)
{
static char Str[] = "xM xD xI";
switch (Bits & BIT_xM)
{
case BIT_MM:
Str[0] = 'M';
break;
case BIT_DM:
Str[0] = 'D';
break;
case BIT_IM:
Str[0] = 'I';
break;
}
switch (Bits & BIT_xD)
{
case BIT_MD:
Str[3] = 'M';
break;
case BIT_DD:
Str[3] = 'D';
break;
}
switch (Bits & BIT_xI)
{
case BIT_MI:
Str[6] = 'M';
break;
case BIT_II:
Str[6] = 'I';
break;
}
return Str;
}
static inline char XChar(char Bits, char cType)
{
switch (cType)
{
case 'M':
{
switch (Bits & BIT_xM)
{
case BIT_MM:
return 'M';
case BIT_DM:
return 'D';
case BIT_IM:
return 'I';
#if DOUBLE_AFFINE
case BIT_EM:
return 'E';
case BIT_JM:
return 'J';
#endif
}
Quit("Huh!?");
return '?';
}
case 'D':
{
switch (Bits & BIT_xD)
{
case BIT_MD:
return 'M';
case BIT_DD:
return 'D';
}
Quit("Huh!?");
return '?';
}
case 'I':
{
switch (Bits & BIT_xI)
{
case BIT_MI:
return 'M';
case BIT_II:
return 'I';
}
Quit("Huh!?");
return '?';
}
#if DOUBLE_AFFINE
case 'E':
{
switch (Bits & BIT_xE)
{
case BIT_ME:
return 'M';
case BIT_EE:
return 'E';
}
Quit("Huh!?");
return '?';
}
case 'J':
{
switch (Bits & BIT_xJ)
{
case BIT_MJ:
return 'M';
case BIT_JJ:
return 'J';
}
Quit("Huh!?");
return '?';
}
#endif
default:
Quit("Huh?");
return '?';
}
}
void BitTraceBack(char **TraceBack, unsigned uLengthA, unsigned uLengthB,
char LastEdge, PWPath &Path)
{
#if TRACE
Log("BitTraceBack\n");
#endif
Path.Clear();
PWEdge Edge;
Edge.uPrefixLengthA = uLengthA;
Edge.uPrefixLengthB = uLengthB;
char Bits = TraceBack[uLengthA][uLengthB];
Edge.cType = LastEdge;
for (;;)
{
#if TRACE
Log("Prepend %c%d.%d\n", Edge.cType, Edge.uPrefixLengthA, Edge.uPrefixLengthB);
#endif
char cSave = Edge.cType;
Edge.cType = XlatEdgeType(cSave);
Path.PrependEdge(Edge);
Edge.cType = cSave;
unsigned PLA = Edge.uPrefixLengthA;
unsigned PLB = Edge.uPrefixLengthB;
char Bits = TraceBack[PLA][PLB];
char NextEdgeType = XChar(Bits, Edge.cType);
#if TRACE
Log("XChar(%s, %c) = %c\n", BitsToStr(Bits), Edge.cType, NextEdgeType);
#endif
switch (Edge.cType)
{
case 'M':
{
if (Edge.uPrefixLengthA == 0)
Quit("BitTraceBack MA=0");
if (Edge.uPrefixLengthB == 0)
Quit("BitTraceBack MA=0");
--(Edge.uPrefixLengthA);
--(Edge.uPrefixLengthB);
break;
}
case 'D':
case 'E':
{
if (Edge.uPrefixLengthA == 0)
Quit("BitTraceBack DA=0");
--(Edge.uPrefixLengthA);
break;
}
case 'I':
case 'J':
{
if (Edge.uPrefixLengthB == 0)
Quit("BitTraceBack IB=0");
--(Edge.uPrefixLengthB);
break;
}
default:
Quit("BitTraceBack: Invalid edge %c", Edge);
}
if (0 == Edge.uPrefixLengthA && 0 == Edge.uPrefixLengthB)
break;
Edge.cType = NextEdgeType;
}
#if TRACE
Path.LogMe();
#endif
}
|