MCPcopy Create free account
hub / github.com/WinMerge/winmerge / CreateVirtualLineToRealLineMap3way

Function CreateVirtualLineToRealLineMap3way

Src/MergeDocDiffSync.cpp:124–241  ·  view source on GitHub ↗

* @brief Create map from virtual line to real line. (3-way) */

Source from the content-addressed store, hash-verified

122 * @brief Create map from virtual line to real line. (3-way)
123 */
124static std::vector<std::array<int, 3>>
125CreateVirtualLineToRealLineMap3way(
126 const DiffMap& diffmap01, const DiffMap& diffmap12, const DiffMap& diffmap20,
127 int nlines0, int nlines1, int nlines2)
128{
129 std::vector<std::array<int, 2>> vlines01 = CreateVirtualLineToRealLineMap(diffmap01, nlines0, nlines1);
130 std::vector<std::array<int, 2>> vlines12 = CreateVirtualLineToRealLineMap(diffmap12, nlines1, nlines2);
131 std::vector<std::array<int, 2>> vlines20 = CreateVirtualLineToRealLineMap(diffmap20, nlines2, nlines0);
132 std::vector<std::array<int, 3>> vlines;
133 vlines.reserve((std::max)({ nlines0, nlines1, nlines2 }) * 3 / 2); // Roughly pre-allocate space for the list.
134 size_t i01 = 0, i12 = 0, i20 = 0;
135 int line0 = 0, line1 = 0, line2 = 0;
136 bool is_vlines20_usable = true;
137 // 1.
138 for (line1 = 0; line1 < nlines1; ++line1)
139 {
140 size_t i01b = i01;
141 size_t i12b = i12;
142 size_t i20b = i20;
143 // 1.1
144 for (; i01 < vlines01.size(); ++i01)
145 if (vlines01[i01][1] == line1)
146 break;
147 for (; i12 < vlines12.size(); ++i12)
148 if (vlines12[i12][0] == line1)
149 break;
150 assert(i01 < vlines01.size() && i12 < vlines12.size());
151 // 1.2
152 bool used_vlines20 = false;
153 if (is_vlines20_usable)
154 {
155 if (vlines12[i12][1] != DiffMap::GHOST_MAP_ENTRY && vlines01[i01][0] != DiffMap::GHOST_MAP_ENTRY)
156 {
157 // 1.2.1
158 line2 = vlines12[i12][1];
159 line0 = vlines01[i01][0];
160 size_t i20tmp;
161 for (i20tmp = i20b; i20tmp < vlines20.size(); ++i20tmp)
162 if (vlines20[i20tmp][0] == line2 && vlines20[i20tmp][1] == line0)
163 break;
164 if (i20tmp < vlines20.size())
165 {
166 // 1.2.1.1
167 for (; i20 < i20tmp; ++i20)
168 vlines.push_back({ vlines20[i20][1], DiffMap::GHOST_MAP_ENTRY, vlines20[i20][0] });
169 ++i20;
170 used_vlines20 = true;
171 }
172 else
173 {
174 // 1.2.1.2
175 is_vlines20_usable = false;
176 }
177 }
178 else
179 {
180 // 1.2.2
181 is_vlines20_usable = false;

Callers 1

AdjustDiffBlocks3wayMethod · 0.85

Calls 6

assertClass · 0.85
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected