1 | #include "muscle.h" |
---|
2 | #include "pwpath.h" |
---|
3 | |
---|
4 | #define TRACE 0 |
---|
5 | |
---|
6 | void DiffPaths(const PWPath &p1, const PWPath &p2, unsigned Edges1[], |
---|
7 | unsigned *ptruDiffCount1, unsigned Edges2[], unsigned *ptruDiffCount2) |
---|
8 | { |
---|
9 | #if TRACE |
---|
10 | Log("DiffPaths\n"); |
---|
11 | Log("p1="); |
---|
12 | p1.LogMe(); |
---|
13 | Log("p2="); |
---|
14 | p2.LogMe(); |
---|
15 | #endif |
---|
16 | const unsigned uEdgeCount1 = p1.GetEdgeCount(); |
---|
17 | const unsigned uEdgeCount2 = p2.GetEdgeCount(); |
---|
18 | |
---|
19 | unsigned uDiffCount1 = 0; |
---|
20 | unsigned uDiffCount2 = 0; |
---|
21 | unsigned uEdgeIndex1 = 0; |
---|
22 | unsigned uEdgeIndex2 = 0; |
---|
23 | const PWEdge *Edge1 = &p1.GetEdge(uEdgeIndex1); |
---|
24 | const PWEdge *Edge2 = &p2.GetEdge(uEdgeIndex2); |
---|
25 | for (;;) |
---|
26 | { |
---|
27 | unsigned uEdgeIndexTop1 = uEdgeIndex1; |
---|
28 | unsigned uEdgeIndexTop2 = uEdgeIndex2; |
---|
29 | Edge1 = &p1.GetEdge(uEdgeIndex1); |
---|
30 | Edge2 = &p2.GetEdge(uEdgeIndex2); |
---|
31 | #if TRACE |
---|
32 | Log("e1[%u] PLA%u PLB%u %c, e2[%u] PLA%u PLB %u %c DC1=%u DC2=%u\n", |
---|
33 | uEdgeIndex1, Edge1->uPrefixLengthA, Edge1->uPrefixLengthB, Edge1->cType, |
---|
34 | uEdgeIndex2, Edge2->uPrefixLengthA, Edge2->uPrefixLengthB, Edge2->cType, |
---|
35 | uDiffCount1, uDiffCount2); |
---|
36 | #endif |
---|
37 | if (Edge1->uPrefixLengthA == Edge2->uPrefixLengthA && |
---|
38 | Edge1->uPrefixLengthB == Edge2->uPrefixLengthB) |
---|
39 | { |
---|
40 | if (!Edge1->Equal(*Edge2)) |
---|
41 | { |
---|
42 | Edges1[uDiffCount1++] = uEdgeIndex1; |
---|
43 | Edges2[uDiffCount2++] = uEdgeIndex2; |
---|
44 | } |
---|
45 | ++uEdgeIndex1; |
---|
46 | ++uEdgeIndex2; |
---|
47 | } |
---|
48 | |
---|
49 | else if (Edge2->uPrefixLengthA < Edge1->uPrefixLengthA || |
---|
50 | Edge2->uPrefixLengthB < Edge1->uPrefixLengthB) |
---|
51 | Edges2[uDiffCount2++] = uEdgeIndex2++; |
---|
52 | |
---|
53 | else if (Edge1->uPrefixLengthA < Edge2->uPrefixLengthA || |
---|
54 | Edge1->uPrefixLengthB < Edge2->uPrefixLengthB) |
---|
55 | Edges1[uDiffCount1++] = uEdgeIndex1++; |
---|
56 | |
---|
57 | if (uEdgeCount1 == uEdgeIndex1) |
---|
58 | { |
---|
59 | while (uEdgeIndex2 < uEdgeCount2) |
---|
60 | Edges2[uDiffCount2++] = uEdgeIndex2++; |
---|
61 | goto Done; |
---|
62 | } |
---|
63 | if (uEdgeCount2 == uEdgeIndex2) |
---|
64 | { |
---|
65 | while (uEdgeIndex1 < uEdgeCount1) |
---|
66 | Edges1[uDiffCount1++] = uEdgeIndex1++; |
---|
67 | goto Done; |
---|
68 | } |
---|
69 | if (uEdgeIndex1 == uEdgeIndexTop1 && uEdgeIndex2 == uEdgeIndexTop2) |
---|
70 | Quit("DiffPaths stuck"); |
---|
71 | } |
---|
72 | Done:; |
---|
73 | #if TRACE |
---|
74 | Log("DiffCount1=%u (%u %u)\n", uDiffCount1, uEdgeCount1, uEdgeCount2); |
---|
75 | Log("Diffs1="); |
---|
76 | for (unsigned i = 0; i < uDiffCount1; ++i) |
---|
77 | { |
---|
78 | const PWEdge e = p1.GetEdge(Edges1[i]); |
---|
79 | Log(" %u=%c%u.%u", Edges1[i], e.cType, e.uPrefixLengthA, e.uPrefixLengthB); |
---|
80 | } |
---|
81 | Log("\n"); |
---|
82 | Log("DiffCount2=%u\n", uDiffCount2); |
---|
83 | Log("Diffs2="); |
---|
84 | for (unsigned i = 0; i < uDiffCount2; ++i) |
---|
85 | { |
---|
86 | const PWEdge e = p2.GetEdge(Edges2[i]); |
---|
87 | Log(" %u=%c%u.%u", Edges2[i], e.cType, e.uPrefixLengthA, e.uPrefixLengthB); |
---|
88 | } |
---|
89 | Log("\n"); |
---|
90 | #endif |
---|
91 | *ptruDiffCount1 = uDiffCount1; |
---|
92 | *ptruDiffCount2 = uDiffCount2; |
---|
93 | } |
---|
94 | |
---|
95 | void TestDiffPaths() |
---|
96 | { |
---|
97 | PWPath p1; |
---|
98 | PWPath p2; |
---|
99 | |
---|
100 | p1.AppendEdge('M', 1, 1); |
---|
101 | p1.AppendEdge('M', 2, 2); |
---|
102 | p1.AppendEdge('M', 3, 3); |
---|
103 | |
---|
104 | p2.AppendEdge('M', 1, 1); |
---|
105 | p2.AppendEdge('D', 2, 1); |
---|
106 | p2.AppendEdge('I', 2, 2); |
---|
107 | p2.AppendEdge('M', 3, 3); |
---|
108 | |
---|
109 | unsigned Edges1[64]; |
---|
110 | unsigned Edges2[64]; |
---|
111 | unsigned uDiffCount1; |
---|
112 | unsigned uDiffCount2; |
---|
113 | DiffPaths(p1, p2, Edges1, &uDiffCount1, Edges2, &uDiffCount2); |
---|
114 | } |
---|