|
| | NameIndex ()=default |
| |
| int | add (const std::string &name) |
| | Add a new name and assign the next sequential index.
|
| |
| int | try_add (const std::string &name) |
| | Non-throwing add.
|
| |
| int | find (std::string_view name) const noexcept |
| | Look up the index for a name (case-insensitive).
|
| |
| std::optional< int > | try_find (std::string_view name) const noexcept |
| | Look up the index (case-insensitive), returning std::optional.
|
| |
| const std::string * | canonical (std::string_view name) const noexcept |
| | Stored (original) spelling for a case-insensitive match.
|
| |
| const std::string & | name_of (int idx) const |
| | Return the name for a given index.
|
| |
| int | size () const noexcept |
| | Number of registered names.
|
| |
| bool | empty () const noexcept |
| | True if no names are registered.
|
| |
| void | reserve (std::size_t n) |
| | Pre-allocate for a known count (avoids rehash during input).
|
| |
| void | clear () noexcept |
| | Remove all entries.
|
| |
| void | pop_back () noexcept |
| | Pop the tail entry — the name added most recently.
|
| |
| bool | rename (int idx, const std::string &newName) noexcept |
| | Rename the entry at idx to newName.
|
| |
| void | remove_at (int idx) noexcept |
| | Remove the entry at idx and rebuild the name→index map.
|
| |
| void | begin_bulk_remove () noexcept |
| | Defer map rebuilds across a batch of remove_at() calls.
|
| |
| void | end_bulk_remove () |
| | Close a begin_bulk_remove() scope; outermost close rebuilds the map once. Unbalanced calls are ignored.
|
| |
| const std::vector< std::string > & | names () const noexcept |
| | Read-only access to the ordered name list.
|
| |
Bidirectional name↔index registry for SWMM objects.
Maintains both a hash map (name→index) and a vector (index→name) so that either direction of lookup is O(1).
Lookups are CASE-INSENSITIVE (ASCII fold), matching the legacy engine's hash table (src/legacy/engine/hash.c UCHAR). Names are stored with their original spelling — name_of()/names() feed the .out ID tables, interface files, and the .inp/GeoPackage writers, which must round-trip the user's spelling byte-identically. Two names differing only in case are therefore the SAME entry; add() treats them as duplicates, exactly as legacy does.
| void openswmm::NameIndex::remove_at |
( |
int | idx | ) |
|
|
inlinenoexcept |
Remove the entry at idx and rebuild the name→index map.
All entries at indices > idx are shifted down by one. The map is rebuilt from scratch — O(n) — which is acceptable since this is only called in BUILDING or OPENED state. No-op if idx is out of range.
Inside a begin_bulk_remove()/end_bulk_remove() scope only the vector entry is erased (index→name stays exact) and the ONE rebuild happens at scope end — deleting K objects then costs one rehash instead of K. That per-delete rehash was the dominant bulk-delete cost on large models (BULK_DELETE_AND_WINDOWS_OPEN_PERF_PLAN_2026-09-01 Phase A1).