#ifndef NTX_MAPINDEX_H #define NTX_MAPINDEX_H #include #include #include #include #include namespace ntx { /** * @brief Bidirektionaler Index: String-Key → size_t Position. * * Verwendet Komposition statt Vererbung. * Key → Index: O(1) via unordered_map. */ class NtxMapIndex { public: NtxMapIndex() = default; // --- Lookup --- std::optional indexOf(const std::string& key) const noexcept; bool containsKey(const std::string& key) const noexcept; // --- Iteration --- /// Iteriert über alle Key→Index Paare. /// Template muss im Header bleiben. template void forEachKey(Fn&& fn) const { for (const auto& [key, idx] : m_keyToIndex) fn(key, idx); } // --- Modification --- void addKey(const std::string& key, size_t index); void removeAt(size_t index); bool removeKey(const std::string& key); bool replaceKey(const std::string& oldKey, const std::string& newKey); bool addAlias(const std::string& existingKey, const std::string& alias); size_t size() const noexcept; bool empty() const noexcept; void clear() noexcept; private: std::unordered_map m_keyToIndex; }; using NtxMapIndexPtr = std::shared_ptr; } // namespace ntx #endif // NTX_MAPINDEX_H