MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / importSet

Method importSet

src/core/map.cpp:159–404  ·  view source on GitHub ↗

This algorithm tries to maintain the relative order of colors.

Source from the content-addressed store, hash-verified

157
158// This algorithm tries to maintain the relative order of colors.
159MapColorMap Map::MapColorSet::importSet(const Map::MapColorSet& other, std::vector< bool >* filter, Map* map)
160{
161 MapColorMap out_pointermap;
162
163 // Determine number of colors to import
164 std::size_t import_count = other.colors.size();
165 if (filter)
166 {
167 Q_ASSERT(filter->size() == other.colors.size());
168
169 for (std::size_t i = 0, end = other.colors.size(); i != end; ++i)
170 {
171 MapColor* color = other.colors[i];
172 if (!(*filter)[i] || out_pointermap.contains(color))
173 {
174 continue;
175 }
176
177 out_pointermap[color] = nullptr; // temporary used as a flag
178
179 // Determine referenced spot colors, and add them to the filter
180 if (color->getSpotColorMethod() == MapColor::CustomColor)
181 {
182 for (const SpotColorComponent& component : color->getComponents())
183 {
184 if (!out_pointermap.contains(component.spot_color))
185 {
186 // Add this spot color to the filter
187 int j = 0;
188 while (other.colors[j] != component.spot_color)
189 ++j;
190 (*filter)[j] = true;
191 out_pointermap[component.spot_color] = nullptr;
192 }
193 }
194 }
195 }
196 import_count = out_pointermap.size();
197 out_pointermap.clear();
198 }
199
200 if (import_count > 0)
201 {
202 colors.reserve(colors.size() + import_count);
203
204 // The conflict resolution algorithm below is simplified by setting
205 // iterator `selected_item` to a real list element which is not related
206 // to the actual color sets we are merging. This is the extra element
207 // identified as `end_of_merge_list`.
208 MapColorSetMergeList merge_list{other.colors.size() + 1};
209 const auto end_of_merge_list = end(merge_list) - 1;
210
211 bool priorities_changed = false;
212
213 // Initialize merge_list
214 auto merge_list_item = merge_list.begin();
215 for (std::size_t i = 0; i < other.colors.size(); ++i)
216 {

Callers 1

importMapMethod · 0.80

Calls 13

getSpotColorMethodMethod · 0.80
getPriorityMethod · 0.80
eraseMethod · 0.80
updateAllObjectsMethod · 0.80
sizeMethod · 0.45
containsMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
equalsMethod · 0.45
addColorMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected