From 22a57f91db9643c551e76b84c43fc56ed5586d40 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 3 Jun 2024 14:36:39 +0300 Subject: [PATCH] Huge refactor: use util::hash_table instead of std::unordered everywhere --- libs/app/include/psemek/app/event_state.hpp | 7 +++---- libs/fonts/include/psemek/fonts/bmfont.hpp | 4 ++-- libs/fonts/include/psemek/fonts/kerned_font.hpp | 2 -- libs/fonts/include/psemek/fonts/msdf_font.hpp | 2 -- libs/geom/include/psemek/geom/mesh.hpp | 3 ++- libs/gfx/include/psemek/gfx/gltf_parser.hpp | 8 ++++---- libs/gfx/include/psemek/gfx/mesh.hpp | 6 ++---- libs/gfx/source/color.cpp | 5 ++--- libs/gfx/source/gltf_mesh.cpp | 6 ++---- libs/gfx/source/gltf_parser.cpp | 3 ++- libs/gfx/source/renderer/deferred.cpp | 4 ++-- libs/log/source/log.cpp | 4 ++-- libs/pcg/include/psemek/pcg/chunked_map.hpp | 4 ++-- libs/pcg/include/psemek/pcg/lazy_perlin.hpp | 4 ++-- libs/rs/source/registry.cpp | 5 ++--- .../include/psemek/ui/impl/component_factory_base.hpp | 7 +++---- libs/util/include/psemek/util/any_set.hpp | 5 +++-- libs/util/include/psemek/util/ecs.hpp | 11 +++++------ libs/util/include/psemek/util/enum.hpp | 8 ++++---- libs/util/include/psemek/util/lru_cache.hpp | 4 ++-- libs/util/include/psemek/util/resource_container.hpp | 4 ++-- .../include/psemek/util/unique_sequential_storage.hpp | 5 +++-- tools/noise-generator/generator.cpp | 3 ++- 23 files changed, 53 insertions(+), 61 deletions(-) diff --git a/libs/app/include/psemek/app/event_state.hpp b/libs/app/include/psemek/app/event_state.hpp index d8738497..ab9fbae0 100644 --- a/libs/app/include/psemek/app/event_state.hpp +++ b/libs/app/include/psemek/app/event_state.hpp @@ -1,8 +1,7 @@ #pragma once #include - -#include +#include namespace psemek::app { @@ -13,8 +12,8 @@ namespace psemek::app bool focus = true; geom::point mouse = {0, 0}; int wheel = 0; - std::unordered_set mouse_button_down; - std::unordered_set key_down; + util::hash_set mouse_button_down; + util::hash_set key_down; }; inline void apply(event_state & state, resize_event const & event) diff --git a/libs/fonts/include/psemek/fonts/bmfont.hpp b/libs/fonts/include/psemek/fonts/bmfont.hpp index 8ab035f9..5d013145 100644 --- a/libs/fonts/include/psemek/fonts/bmfont.hpp +++ b/libs/fonts/include/psemek/fonts/bmfont.hpp @@ -1,10 +1,10 @@ #pragma once #include +#include #include #include -#include namespace psemek::fonts { @@ -25,7 +25,7 @@ namespace psemek::fonts std::string name; geom::vector size; int baseline; - std::unordered_map glyphs; + util::hash_map glyphs; float sdf_scale = 0.f; // Parse JSON font info generated by BMFont or msdf-bmfont diff --git a/libs/fonts/include/psemek/fonts/kerned_font.hpp b/libs/fonts/include/psemek/fonts/kerned_font.hpp index 305cc674..2f572a97 100644 --- a/libs/fonts/include/psemek/fonts/kerned_font.hpp +++ b/libs/fonts/include/psemek/fonts/kerned_font.hpp @@ -3,8 +3,6 @@ #include #include -#include - namespace psemek::fonts { diff --git a/libs/fonts/include/psemek/fonts/msdf_font.hpp b/libs/fonts/include/psemek/fonts/msdf_font.hpp index 27de94e9..3963d5be 100644 --- a/libs/fonts/include/psemek/fonts/msdf_font.hpp +++ b/libs/fonts/include/psemek/fonts/msdf_font.hpp @@ -3,8 +3,6 @@ #include #include -#include - namespace psemek::fonts { diff --git a/libs/geom/include/psemek/geom/mesh.hpp b/libs/geom/include/psemek/geom/mesh.hpp index 50eec89d..2f5d8ef0 100644 --- a/libs/geom/include/psemek/geom/mesh.hpp +++ b/libs/geom/include/psemek/geom/mesh.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -170,7 +171,7 @@ namespace psemek::geom return e; }; - std::unordered_map midpoints; + util::hash_map midpoints; auto add_midpoint = [&](Index i0, Index i1) { diff --git a/libs/gfx/include/psemek/gfx/gltf_parser.hpp b/libs/gfx/include/psemek/gfx/gltf_parser.hpp index 59394afd..1a117e31 100644 --- a/libs/gfx/include/psemek/gfx/gltf_parser.hpp +++ b/libs/gfx/include/psemek/gfx/gltf_parser.hpp @@ -7,12 +7,12 @@ #include #include #include +#include #include #include #include #include -#include namespace psemek::gfx { @@ -20,7 +20,7 @@ namespace psemek::gfx struct gltf_asset { using extra = std::variant, std::string>; - using extras_map = std::unordered_map; + using extras_map = util::hash_map; struct node { @@ -182,8 +182,8 @@ namespace psemek::gfx std::vector buffers; std::vector lights; // KHR_lights_punctual - std::unordered_map node_index; // node by name - std::unordered_map material_index; // material by name + util::hash_map node_index; // node by name + util::hash_map material_index; // material by name struct animation_and_channel { diff --git a/libs/gfx/include/psemek/gfx/mesh.hpp b/libs/gfx/include/psemek/gfx/mesh.hpp index f7658335..b45e34f1 100644 --- a/libs/gfx/include/psemek/gfx/mesh.hpp +++ b/libs/gfx/include/psemek/gfx/mesh.hpp @@ -14,11 +14,9 @@ #include #include +#include #include -#include -#include -#include namespace psemek::gfx { @@ -348,7 +346,7 @@ namespace psemek::gfx } using pose_ref = util::span const>; - using pose_library = std::unordered_map; + using pose_library = util::hash_map; struct imported_mesh { diff --git a/libs/gfx/source/color.cpp b/libs/gfx/source/color.cpp index 2fb44d38..3dd3d80f 100644 --- a/libs/gfx/source/color.cpp +++ b/libs/gfx/source/color.cpp @@ -1,11 +1,10 @@ #include - -#include +#include namespace psemek::gfx { - static std::unordered_map const named_colors + static util::hash_map const named_colors { {"black", {0, 0, 0, 255}}, {"white", {255, 255, 255, 255}}, diff --git a/libs/gfx/source/gltf_mesh.cpp b/libs/gfx/source/gltf_mesh.cpp index 105e7fec..e52fa77e 100644 --- a/libs/gfx/source/gltf_mesh.cpp +++ b/libs/gfx/source/gltf_mesh.cpp @@ -3,11 +3,9 @@ #include #include #include +#include #include -#include -#include - namespace psemek::gfx { @@ -75,7 +73,7 @@ namespace psemek::gfx std::vector textures_; std::vector buffers_; std::vector> drawables_; - std::unordered_map meshes_; + util::hash_map meshes_; }; gltf_mesh_impl::gltf_mesh_impl(gltf_asset const & asset, std::function uri_loader) diff --git a/libs/gfx/source/gltf_parser.cpp b/libs/gfx/source/gltf_parser.cpp index d8620988..932368a2 100644 --- a/libs/gfx/source/gltf_parser.cpp +++ b/libs/gfx/source/gltf_parser.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -70,7 +71,7 @@ namespace psemek::gfx throw util::exception(util::to_string("Unknown accessor component type: ", type)); } - static std::unordered_set supported_extensions = + static util::hash_set const supported_extensions = { "KHR_lights_punctual", "KHR_materials_emissive_strength" diff --git a/libs/gfx/source/renderer/deferred.cpp b/libs/gfx/source/renderer/deferred.cpp index 27b1f4c8..d24ac39a 100644 --- a/libs/gfx/source/renderer/deferred.cpp +++ b/libs/gfx/source/renderer/deferred.cpp @@ -27,10 +27,10 @@ #include #include +#include #include #include -#include namespace psemek::gfx { @@ -1046,7 +1046,7 @@ void main(){} struct bin { - std::unordered_map, objects_bucket> buckets; + util::hash_map, objects_bucket> buckets; geom::box bbox; bool contains_near_clip = false; float camera_separation; diff --git a/libs/log/source/log.cpp b/libs/log/source/log.cpp index 4e845ff6..c5177a5f 100644 --- a/libs/log/source/log.cpp +++ b/libs/log/source/log.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -9,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -24,7 +24,7 @@ namespace psemek::log std::atomic max_thread_name_length = 3; std::mutex thread_names_mutex; - std::unordered_map thread_names; + util::hash_map thread_names; std::mutex sinks_mutex; std::vector> sinks; diff --git a/libs/pcg/include/psemek/pcg/chunked_map.hpp b/libs/pcg/include/psemek/pcg/chunked_map.hpp index c1695567..b4bf598b 100644 --- a/libs/pcg/include/psemek/pcg/chunked_map.hpp +++ b/libs/pcg/include/psemek/pcg/chunked_map.hpp @@ -2,9 +2,9 @@ #include #include +#include #include -#include #include namespace psemek::pcg @@ -68,7 +68,7 @@ namespace psemek::pcg private: int const chunk_size_; generator_func generator_; - mutable std::unordered_map, util::array> chunks_; + mutable util::hash_map, util::array> chunks_; }; diff --git a/libs/pcg/include/psemek/pcg/lazy_perlin.hpp b/libs/pcg/include/psemek/pcg/lazy_perlin.hpp index c0f43f20..58367c1a 100644 --- a/libs/pcg/include/psemek/pcg/lazy_perlin.hpp +++ b/libs/pcg/include/psemek/pcg/lazy_perlin.hpp @@ -2,11 +2,11 @@ #include #include +#include #include #include -#include #include namespace psemek::pcg @@ -101,7 +101,7 @@ namespace psemek::pcg private: int const grid_size_; - mutable std::unordered_map, geom::vector> grid_; + mutable util::hash_map, geom::vector> grid_; generator_func gen_; geom::vector grid_at(geom::vector const & c) const diff --git a/libs/rs/source/registry.cpp b/libs/rs/source/registry.cpp index e37e0a60..82fe67b2 100644 --- a/libs/rs/source/registry.cpp +++ b/libs/rs/source/registry.cpp @@ -1,12 +1,11 @@ #include #include +#include #include -#include #include #include -#include namespace psemek::rs { @@ -34,7 +33,7 @@ namespace psemek::rs auto & name_map() { - static std::unordered_map instance; + static util::hash_map instance; return instance; } diff --git a/libs/ui/include/psemek/ui/impl/component_factory_base.hpp b/libs/ui/include/psemek/ui/impl/component_factory_base.hpp index 95bb76e1..0ea05390 100644 --- a/libs/ui/include/psemek/ui/impl/component_factory_base.hpp +++ b/libs/ui/include/psemek/ui/impl/component_factory_base.hpp @@ -7,11 +7,10 @@ #include #include #include +#include #include -#include #include -#include namespace psemek::ui::impl { @@ -92,7 +91,7 @@ namespace psemek::ui::impl impl->set_children_token(typed_value.children.subscribe([this, impl = impl.get()](std::vector const & children_values){ impl->release_child_tokens(); - std::unordered_map> child_by_key; + util::hash_map> child_by_key; auto old_children = impl->release_children(); { @@ -159,7 +158,7 @@ namespace psemek::ui::impl } private: - std::unordered_map(std::unique_ptr, std::any const &)>> type_factories_; + util::hash_map(std::unique_ptr, std::any const &)>> type_factories_; }; } diff --git a/libs/util/include/psemek/util/any_set.hpp b/libs/util/include/psemek/util/any_set.hpp index 6017f7a6..643e955a 100644 --- a/libs/util/include/psemek/util/any_set.hpp +++ b/libs/util/include/psemek/util/any_set.hpp @@ -1,8 +1,9 @@ #pragma once +#include + #include #include -#include namespace psemek::util { @@ -34,7 +35,7 @@ namespace psemek::util void remove(); private: - std::unordered_map storage_; + util::hash_map storage_; }; template diff --git a/libs/util/include/psemek/util/ecs.hpp b/libs/util/include/psemek/util/ecs.hpp index 3886a5d1..3109b272 100644 --- a/libs/util/include/psemek/util/ecs.hpp +++ b/libs/util/include/psemek/util/ecs.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -18,8 +19,6 @@ #include #include -#include - namespace psemek::util { @@ -710,17 +709,17 @@ namespace psemek::util private: std::vector> species_; - std::unordered_map species_by_name_; + util::hash_map species_by_name_; - std::unordered_map>> event_subscribers_; + util::hash_map>> event_subscribers_; std::vector> species_constructors_; std::vector> constructors_; - std::unordered_map>> private_constructors_; + util::hash_map>> private_constructors_; std::vector> destructors_; - std::unordered_map>> private_destructors_; + util::hash_map>> private_destructors_; }; template diff --git a/libs/util/include/psemek/util/enum.hpp b/libs/util/include/psemek/util/enum.hpp index fba931d2..44ed9047 100644 --- a/libs/util/include/psemek/util/enum.hpp +++ b/libs/util/include/psemek/util/enum.hpp @@ -5,13 +5,13 @@ #include #include +#include #include -#include -#include #include #include -#include +#include +#include namespace psemek::util { @@ -104,7 +104,7 @@ namespace psemek::util } \ } \ inline std::optional BOOST_PP_CAT(name, _from_string)(::std::string_view str) { \ - static const ::std::unordered_map<::std::string_view, name> map = { \ + static const ::psemek::util::hash_map<::std::string_view, name> map = { \ BOOST_PP_SEQ_FOR_EACH(psemek_declare_enum_detail_from_string, name, values) \ }; \ auto it = map.find(str); if (it == map.end()) return std::nullopt; return it->second; \ diff --git a/libs/util/include/psemek/util/lru_cache.hpp b/libs/util/include/psemek/util/lru_cache.hpp index 01e9760b..751ea6b7 100644 --- a/libs/util/include/psemek/util/lru_cache.hpp +++ b/libs/util/include/psemek/util/lru_cache.hpp @@ -1,10 +1,10 @@ #pragma once #include +#include #include #include -#include namespace psemek::util { @@ -79,7 +79,7 @@ namespace psemek::util // list_ contains non-removable items first, then all removable items std::list list_; iterator removable_begin_ = list_.end(); - std::unordered_map map_; + util::hash_map map_; iterator find_safe(Key const & key); const_iterator find_safe(Key const & key) const; diff --git a/libs/util/include/psemek/util/resource_container.hpp b/libs/util/include/psemek/util/resource_container.hpp index 97596920..ccfd31bd 100644 --- a/libs/util/include/psemek/util/resource_container.hpp +++ b/libs/util/include/psemek/util/resource_container.hpp @@ -1,12 +1,12 @@ #pragma once #include +#include #include #include #include #include -#include #include namespace psemek::util @@ -82,7 +82,7 @@ namespace psemek::util private: std::vector objects_; - std::unordered_map name_map_; + util::hash_map name_map_; }; } diff --git a/libs/util/include/psemek/util/unique_sequential_storage.hpp b/libs/util/include/psemek/util/unique_sequential_storage.hpp index 8c643e6a..585a09f6 100644 --- a/libs/util/include/psemek/util/unique_sequential_storage.hpp +++ b/libs/util/include/psemek/util/unique_sequential_storage.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include + #include #include @@ -30,7 +31,7 @@ namespace psemek::util } private: - std::unordered_map value_to_index_; + util::hash_map value_to_index_; std::vector index_to_value_; }; diff --git a/tools/noise-generator/generator.cpp b/tools/noise-generator/generator.cpp index 7d5e1663..cc10d191 100644 --- a/tools/noise-generator/generator.cpp +++ b/tools/noise-generator/generator.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include using namespace psemek; @@ -198,7 +199,7 @@ std::optional parse_bool(std::string const & str) int main(int argc, char * argv[]) { - std::unordered_map values; + util::hash_map values; values["dim"] = "2"; values["sizex"] = "256"; values["sizey"] = "256";