diff --git a/deps/ox/src/ox/std/smallmap.hpp b/deps/ox/src/ox/std/smallmap.hpp index 7355d32d..00f8659a 100644 --- a/deps/ox/src/ox/std/smallmap.hpp +++ b/deps/ox/src/ox/std/smallmap.hpp @@ -62,6 +62,9 @@ class SmallMap { [[nodiscard]] constexpr Vector keys() const noexcept; + [[nodiscard]] + constexpr Vector values() const noexcept; + [[nodiscard]] constexpr K const&key(size_t i) const noexcept; @@ -91,6 +94,9 @@ class SmallMap { template constexpr Pair *access(PairVector &pairs, KK const&key, bool &isNew); + template + constexpr Pair *accessNoCreate(PairVector &pairs, KK const&key); + }; template @@ -138,8 +144,7 @@ constexpr T &SmallMap::operator[](MaybeView_t const&k) { template constexpr Result SmallMap::at(MaybeView_t const&k) noexcept { - bool isNew{}; - auto p = access(m_pairs, k, isNew); + auto const p = accessNoCreate(m_pairs, k); if (!p) { return {nullptr, ox::Error(1, "value not found for given key")}; } @@ -189,6 +194,16 @@ constexpr Vector SmallMap::keys() const noexcept { return keys; } +template +constexpr Vector SmallMap::values() const noexcept { + ox::Vector keys; + keys.reserve(m_pairs.size()); + for (auto const&p : m_pairs) { + keys.emplace_back(p.key); + } + return keys; +} + template constexpr K const&SmallMap::key(size_t i) const noexcept { return m_pairs[i].key; @@ -247,6 +262,18 @@ constexpr typename SmallMap::Pair *SmallMap::acces return &pairs.emplace_back(); } +template +template +constexpr typename SmallMap::Pair *SmallMap::accessNoCreate( + PairVector &pairs, KK const&k) { + for (auto &p : pairs) { + if (p.key == k) { + return &p; + } + } + return nullptr; +} + template constexpr Error model(T *io, ox::CommonPtrWith> auto *obj) noexcept { using Map = SmallMap;