| 123 | } |
| 124 | |
| 125 | void Base::UniqueNameManager::removeExactName(std::string_view name) |
| 126 | { |
| 127 | auto duplicateCountFound = duplicateCounts.find(name); |
| 128 | if (duplicateCountFound != duplicateCounts.end()) { |
| 129 | // The name has duplicates. Decrement the duplicate count. |
| 130 | if (--duplicateCountFound->second <= 1) { |
| 131 | // After removal, there are no duplicates, only a single instance. |
| 132 | // Remove the duplicateCounts entry. |
| 133 | duplicateCounts.erase(duplicateCountFound); |
| 134 | } |
| 135 | return; |
| 136 | } |
| 137 | const auto [namePrefix, nameSuffix, digitCount, digitsValue] = decomposeName(name); |
| 138 | std::string baseName {namePrefix}; |
| 139 | baseName += nameSuffix; |
| 140 | auto baseNameEntry = uniqueSeeds.find(baseName); |
| 141 | if (baseNameEntry == uniqueSeeds.end()) { |
| 142 | // name must not be registered, so nothing to do. |
| 143 | return; |
| 144 | } |
| 145 | auto& digitValueSets = baseNameEntry->second; |
| 146 | if (digitCount >= digitValueSets.size()) { |
| 147 | // First use of this digitCount, name must not be registered, so nothing to do. |
| 148 | return; |
| 149 | } |
| 150 | digitValueSets[digitCount].remove(digitsValue); |
| 151 | // an element of digitValueSets may now be newly empty and so may other elements below it |
| 152 | // Prune off all such trailing empty entries. |
| 153 | auto lastNonemptyEntry |
| 154 | = std::find_if(digitValueSets.crbegin(), digitValueSets.crend(), [](auto& it) { |
| 155 | return !it.empty(); |
| 156 | }); |
| 157 | if (lastNonemptyEntry == digitValueSets.crend()) { |
| 158 | // All entries are empty, so the entire baseName can be forgotten. |
| 159 | uniqueSeeds.erase(baseName); |
| 160 | } |
| 161 | else { |
| 162 | digitValueSets.resize(digitValueSets.crend() - lastNonemptyEntry); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | bool Base::UniqueNameManager::containsName(std::string_view name) const |
| 167 | { |