diff --git a/include/geode/basic/attribute_manager.hpp b/include/geode/basic/attribute_manager.hpp index b1da00dc7..60907632c 100644 --- a/include/geode/basic/attribute_manager.hpp +++ b/include/geode/basic/attribute_manager.hpp @@ -60,7 +60,7 @@ namespace geode [[nodiscard]] std::shared_ptr< AttributeBase > find_generic_attribute( std::string_view name ) const { - absl::ReaderMutexLock lock{ &mutex() }; + absl::ReaderMutexLock lock{ mutex() }; return find_attribute_base( name ); } @@ -74,7 +74,7 @@ namespace geode [[nodiscard]] std::shared_ptr< ReadOnlyAttribute< T > > find_attribute( std::string_view name ) const { - absl::ReaderMutexLock lock{ &mutex() }; + absl::ReaderMutexLock lock{ mutex() }; auto attribute = std::dynamic_pointer_cast< ReadOnlyAttribute< T > >( find_attribute_base( name ) ); @@ -110,7 +110,7 @@ namespace geode AttributeProperties properties ) { { - absl::ReaderMutexLock lock{ &mutex() }; + absl::ReaderMutexLock lock{ mutex() }; auto attribute = find_attribute_base( name ); auto typed_attribute = std::dynamic_pointer_cast< Attribute< T > >( attribute ); @@ -119,7 +119,7 @@ namespace geode return typed_attribute; } } - absl::MutexLock lock{ &mutex() }; + absl::MutexLock lock{ mutex() }; auto attribute = find_attribute_base( name ); auto typed_attribute = std::dynamic_pointer_cast< Attribute< T > >( attribute ); diff --git a/include/geode/basic/cached_value.hpp b/include/geode/basic/cached_value.hpp index 27ce2bf71..4294f1e6f 100644 --- a/include/geode/basic/cached_value.hpp +++ b/include/geode/basic/cached_value.hpp @@ -74,7 +74,7 @@ namespace geode { if( !computed_ ) { - absl::MutexLock lock{ &mutex_ }; + absl::MutexLock lock{ mutex_ }; if( !computed_ ) { value_ = computer( std::forward< Args >( args )... ); diff --git a/include/geode/basic/mapping.hpp b/include/geode/basic/mapping.hpp index fb520cb3b..d4890d593 100644 --- a/include/geode/basic/mapping.hpp +++ b/include/geode/basic/mapping.hpp @@ -23,8 +23,9 @@ #pragma once -#include +#include #include +#include #include @@ -71,13 +72,13 @@ namespace geode return out2in_.at( out ); } - [[nodiscard]] const absl::flat_hash_map< T1, Storage< T2 > >& + [[nodiscard]] const absl::linked_hash_map< T1, Storage< T2 > >& in2out_map() const { return in2out_; } - [[nodiscard]] const absl::flat_hash_map< T2, Storage< T1 > >& + [[nodiscard]] const absl::linked_hash_map< T2, Storage< T1 > >& out2in_map() const { return out2in_; @@ -100,19 +101,21 @@ namespace geode return static_cast< index_t >( out2in_.size() ); } - [[nodiscard]] absl::flat_hash_map< T1, Storage< T2 > >& in2out_mapping() + [[nodiscard]] absl::linked_hash_map< T1, Storage< T2 > >& + in2out_mapping() { return in2out_; } - [[nodiscard]] absl::flat_hash_map< T2, Storage< T1 > >& out2in_mapping() + [[nodiscard]] absl::linked_hash_map< T2, Storage< T1 > >& + out2in_mapping() { return out2in_; } private: - absl::flat_hash_map< T1, Storage< T2 > > in2out_; - absl::flat_hash_map< T2, Storage< T1 > > out2in_; + absl::linked_hash_map< T1, Storage< T2 > > in2out_; + absl::linked_hash_map< T2, Storage< T1 > > out2in_; }; template < typename T > @@ -225,6 +228,10 @@ namespace geode } auto& out_map = this->out2in_mapping().at( out ); const auto itr2 = absl::c_find( out_map, in ); + if( itr2 == out_map.end() ) + { + return; + } out_map.erase( itr2 ); if( this->out2in( out ).empty() ) { diff --git a/include/geode/model/mixin/core/component_type.hpp b/include/geode/model/mixin/core/component_type.hpp index 41b99333e..0a27d659b 100644 --- a/include/geode/model/mixin/core/component_type.hpp +++ b/include/geode/model/mixin/core/component_type.hpp @@ -84,6 +84,15 @@ namespace geode return type_.get() == other.type_.get() && id_ == other.id_; } + [[nodiscard]] bool operator<( const ComponentID& other ) const + { + if( type_.get() != other.type_.get() ) + { + return type_.get() < other.type_.get(); + } + return id_ < other.id_; + } + [[nodiscard]] std::string string() const { return absl::StrCat( type_.get(), " ", id_.string() ); diff --git a/include/geode/model/mixin/core/detail/components_storage.hpp b/include/geode/model/mixin/core/detail/components_storage.hpp index e791ef5e8..61f9781ba 100644 --- a/include/geode/model/mixin/core/detail/components_storage.hpp +++ b/include/geode/model/mixin/core/detail/components_storage.hpp @@ -27,8 +27,8 @@ #include #include -#include #include +#include #include #include @@ -52,7 +52,7 @@ namespace geode { public: using ComponentPtr = std::unique_ptr< Component >; - using ComponentsStore = absl::btree_map< uuid, ComponentPtr >; + using ComponentsStore = absl::linked_hash_map< uuid, ComponentPtr >; using Iterator = typename ComponentsStore::const_iterator; [[nodiscard]] index_t nb_components() const diff --git a/include/geode/model/mixin/core/vertex_identifier.hpp b/include/geode/model/mixin/core/vertex_identifier.hpp index 5d7e03be3..324408fe9 100644 --- a/include/geode/model/mixin/core/vertex_identifier.hpp +++ b/include/geode/model/mixin/core/vertex_identifier.hpp @@ -57,6 +57,8 @@ namespace geode [[nodiscard]] bool operator==( const ComponentMeshVertex& other ) const; + [[nodiscard]] bool operator<( const ComponentMeshVertex& other ) const; + template < typename Archive > void serialize( Archive& archive ); diff --git a/src/geode/basic/CMakeLists.txt b/src/geode/basic/CMakeLists.txt index 93b50b166..530c02228 100644 --- a/src/geode/basic/CMakeLists.txt +++ b/src/geode/basic/CMakeLists.txt @@ -109,6 +109,7 @@ add_geode_library( "internal/array_impl.hpp" PUBLIC_DEPENDENCIES absl::flat_hash_map + absl::linked_hash_map absl::strings absl::stacktrace absl::symbolize diff --git a/src/geode/basic/attribute_manager.cpp b/src/geode/basic/attribute_manager.cpp index b568cee7e..0989d08b8 100644 --- a/src/geode/basic/attribute_manager.cpp +++ b/src/geode/basic/attribute_manager.cpp @@ -163,7 +163,7 @@ namespace geode void delete_attribute( std::string_view name ) { - absl::MutexLock lock{ &mutex_ }; + absl::MutexLock lock{ mutex_ }; const auto attribute_it = attributes_.find( name ); if( attribute_it != attributes_.end() ) { diff --git a/src/geode/mesh/helpers/convert_surface_mesh.cpp b/src/geode/mesh/helpers/convert_surface_mesh.cpp index 645948cc3..8da322e02 100644 --- a/src/geode/mesh/helpers/convert_surface_mesh.cpp +++ b/src/geode/mesh/helpers/convert_surface_mesh.cpp @@ -23,6 +23,8 @@ #include +#include + #include #include diff --git a/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp b/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp index e458e109a..bde7de751 100644 --- a/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp +++ b/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp @@ -139,7 +139,6 @@ namespace geode ElementsMapping duplicate_points( const SolidInfo& solid_info ) { ElementsMapping vertices_mapping; - vertices_mapping.reserve( solid_.nb_vertices() ); for( const auto vertex_id : Range{ solid_.nb_vertices() } ) { vertices_mapping.map( vertex_id, vertex_id ); diff --git a/src/geode/model/mixin/core/vertex_identifier.cpp b/src/geode/model/mixin/core/vertex_identifier.cpp index 152ca4282..a698b9e5d 100644 --- a/src/geode/model/mixin/core/vertex_identifier.cpp +++ b/src/geode/model/mixin/core/vertex_identifier.cpp @@ -78,6 +78,16 @@ namespace geode return component_id == other.component_id && vertex == other.vertex; } + bool ComponentMeshVertex::operator<( + const ComponentMeshVertex& other ) const + { + if( component_id != other.component_id ) + { + return component_id < other.component_id; + } + return vertex < other.vertex; + } + template < typename Archive > void ComponentMeshVertex::serialize( Archive& archive ) {