erases map_pos from its group, and deletes mappings IFF the group is empty
| 279 | |
| 280 | // erases map_pos from its group, and deletes mappings IFF the group is empty |
| 281 | void 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 |
| 312 | Groups::const_iterator ChannelGroups::find(const df::coord &map_pos) const { |