diff --git a/common/view/view_group.cpp b/common/view/view_group.cpp index c8b888a119..f403f630e9 100644 --- a/common/view/view_group.cpp +++ b/common/view/view_group.cpp @@ -112,7 +112,7 @@ void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const const std::vector drawList = updateDrawList(); - std::unordered_map> layer_item_map; + std::map> layer_item_map; // Build a list of layers used by the items in the group for( VIEW_ITEM* item : drawList ) @@ -123,13 +123,6 @@ void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const for( int i = 0; i < item_layers_count; i++ ) { wxCHECK2_MSG( item_layers[i] <= LAYER_ID_COUNT, continue, wxT( "Invalid item layer" ) ); - - if( layer_item_map.count( item_layers[i] ) == 0 ) - { - layer_item_map.emplace( std::make_pair( item_layers[i], - std::vector() ) ); - } - layer_item_map[ item_layers[i] ].push_back( item ); } } diff --git a/common/wx_stl_compat.cpp b/common/wx_stl_compat.cpp index eac3fab4d2..b744b8fb70 100644 --- a/common/wx_stl_compat.cpp +++ b/common/wx_stl_compat.cpp @@ -29,16 +29,6 @@ size_t std::hash::operator()( const wxString& s ) const #endif #ifdef USE_KICAD_WXPOINT_LESS_AND_HASH -size_t std::hash::operator() ( const wxPoint& k ) const -{ - auto xhash = std::hash()( k.x ); - - // 0x9e3779b9 is 2^33 / ( 1 + sqrt(5) ) - // Adding this value ensures that consecutive bits of y will not be close to each other - // decreasing the likelihood of hash collision in similar values of x and y - return xhash ^ ( std::hash()( k.y ) + 0x9e3779b9 + ( xhash << 6 ) + ( xhash >> 2 ) ); -} - bool std::less::operator()( const wxPoint& aA, const wxPoint& aB ) const { if( aA.x == aB.x ) diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index b061585519..cd65703906 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -411,7 +411,7 @@ int ERC_TESTER::TestNoConnectPins() for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() ) { - std::unordered_map> pinMap; + std::map> pinMap; for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) ) { @@ -863,4 +863,4 @@ int ERC_TESTER::TestOffGridEndpoints( int aGridSize ) } return err_count; -} \ No newline at end of file +} diff --git a/include/core/wx_stl_compat.h b/include/core/wx_stl_compat.h index c6ae56c21d..0b6710b49b 100644 --- a/include/core/wx_stl_compat.h +++ b/include/core/wx_stl_compat.h @@ -43,7 +43,7 @@ namespace std { template <> struct hash { - size_t operator() ( const wxPoint& k ) const; + size_t operator() ( const wxPoint& k ) const = delete; }; } diff --git a/libs/kimath/include/math/vector2d.h b/libs/kimath/include/math/vector2d.h index 811da14ef2..a8958f5aaf 100644 --- a/libs/kimath/include/math/vector2d.h +++ b/libs/kimath/include/math/vector2d.h @@ -611,13 +611,17 @@ typedef VECTOR2 VECTOR2U; namespace std { // Required to enable correct use in std::map/unordered_map + // DO NOT USE hash tables with VECTOR2 elements. It is inefficient + // and degenerates to a linear search. Use the std::map/std::set + // trees instead that utilize the less operator below + // This function is purposely deleted after substantial testing template <> struct hash { - size_t operator()( const VECTOR2I& k ) const; + size_t operator()( const VECTOR2I& k ) const = delete; }; - // Required to enable use of std::hash with maps + // Required to enable use of std::hash with maps. template <> struct less { diff --git a/libs/kimath/src/math/vector2.cpp b/libs/kimath/src/math/vector2.cpp index 29da329fe7..deb14c6231 100644 --- a/libs/kimath/src/math/vector2.cpp +++ b/libs/kimath/src/math/vector2.cpp @@ -19,22 +19,10 @@ #include - -size_t std::hash::operator()( const VECTOR2I& k ) const -{ - auto xhash = std::hash()( k.x ); - - // 0x9e3779b9 is 2^33 / ( 1 + sqrt(5) ) - // Adding this value ensures that consecutive bits of y will not be close to each other - // decreasing the likelihood of hash collision in similar values of x and y - return xhash ^ ( std::hash()( k.y ) + 0x9e3779b9 + ( xhash << 6 ) + ( xhash >> 2 ) ); -} - - bool std::less::operator()( const VECTOR2I& aA, const VECTOR2I& aB ) const { if( aA.x == aB.x ) return aA.y < aB.y; return aA.x < aB.x; -} \ No newline at end of file +} diff --git a/pcbnew/drc/drc_engine.h b/pcbnew/drc/drc_engine.h index 06cf0694ff..33ba092e6e 100644 --- a/pcbnew/drc/drc_engine.h +++ b/pcbnew/drc/drc_engine.h @@ -243,7 +243,7 @@ protected: bool m_testFootprints; // constraint -> rule -> provider - std::unordered_map*> m_constraintMap; + std::map*> m_constraintMap; DRC_VIOLATION_HANDLER m_violationHandler; REPORTER* m_reporter; diff --git a/pcbnew/drc/drc_test_provider_copper_clearance.cpp b/pcbnew/drc/drc_test_provider_copper_clearance.cpp index ded5baf1df..d3f4f9730b 100644 --- a/pcbnew/drc/drc_test_provider_copper_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_copper_clearance.cpp @@ -854,7 +854,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones() } // Iterate through all the segments of refSmoothedPoly - std::unordered_map conflictPoints; + std::map conflictPoints; for( auto refIt = smoothed_polys[ia].IterateSegmentsWithHoles(); refIt; refIt++ ) { diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 7d9ccb1699..50159325a1 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1140,12 +1140,12 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks( auto connectivity = board()->GetConnectivity(); - std::unordered_map> trackMap; - std::unordered_map viaMap; - std::unordered_map padMap; - std::set startPadSet; - std::vector cleanupItems; - std::vector> activePts; + std::map> trackMap; + std::map viaMap; + std::map padMap; + std::set startPadSet; + std::vector cleanupItems; + std::vector> activePts; for( BOARD_CONNECTED_ITEM* startItem : aStartItems ) {