MCPcopy Create free account
hub / github.com/DFHack/dfhack / remove

Method remove

plugins/channel-safely/channel-groups.cpp:281–309  ·  view source on GitHub ↗

erases map_pos from its group, and deletes mappings IFF the group is empty

Source from the content-addressed store, hash-verified

279
280// erases map_pos from its group, and deletes mappings IFF the group is empty
281void ChannelGroups::remove(const df::coord &map_pos) {
282 // we don't need to do anything if the position isn't in a group (granted, that should never be the case)
283 INFO(groups).print(" remove()\n");
284 if (groups_map.count(map_pos)) {
285 INFO(groups).print(" -> found group\n");
286 // get the group, and map_pos' block*
287 int group_index = groups_map.find(map_pos)->second;
288 Group &group = groups[group_index];
289 // erase map_pos from the group
290 INFO(groups).print(" -> erase(" COORD ")\n", COORDARGS(map_pos));
291 group.erase(map_pos);
292 groups_map.erase(map_pos);
293 // clean up if the group is empty
294 if (group.empty()) {
295 WARN(groups).print(" -> group is empty\n");
296 // erase `coord -> group group_index` mappings
297 for (auto iter = groups_map.begin(); iter != groups_map.end();) {
298 if (group_index == iter->second) {
299 iter = groups_map.erase(iter);
300 continue;
301 }
302 ++iter;
303 }
304 // flag the `groups` group_index as available
305 free_spots.insert(group_index);
306 }
307 }
308 INFO(groups).print(" remove() exits\n");
309}
310
311// finds a group corresponding to a map position if one exists
312Groups::const_iterator ChannelGroups::find(const df::coord &map_pos) const {

Callers 1

mark_doneMethod · 0.45

Calls 8

printMethod · 0.45
countMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected