Utilize our combine_hash routine for multiple hash
We should be using the one routine every time we want to build a hash from indepedent values rather than rebuilding it differently in multiple places
This commit is contained in:
parent
06786c34d7
commit
146495672e
|
@ -28,7 +28,7 @@
|
|||
#include <bitmaps.h>
|
||||
#include <bitmap_store.h>
|
||||
#include <bitmaps/bitmap_info.h>
|
||||
#include <hash_eda.h>
|
||||
#include <hash.h>
|
||||
#include <kiplatform/ui.h>
|
||||
#include <paths.h>
|
||||
#include <pgm_base.h>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
#include <hash_eda.h>
|
||||
|
||||
#include <hash.h>
|
||||
#include <footprint.h>
|
||||
#include <fp_text.h>
|
||||
#include <fp_textbox.h>
|
||||
|
@ -77,14 +77,11 @@ size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags )
|
|||
{
|
||||
const PAD* pad = static_cast<const PAD*>( aItem );
|
||||
|
||||
ret = hash<int>{}( static_cast<int>( pad->GetShape() ) << 16 );
|
||||
hash_combine( ret, pad->GetDrillShape() << 18 );
|
||||
hash_combine( ret, pad->GetSize().x << 8 );
|
||||
hash_combine( ret, pad->GetSize().y << 9 );
|
||||
hash_combine( ret, pad->GetOffset().x << 6 );
|
||||
hash_combine( ret, pad->GetOffset().y << 7 );
|
||||
hash_combine( ret, pad->GetDelta().x << 4 );
|
||||
hash_combine( ret, pad->GetDelta().y << 5 );
|
||||
ret = hash<int>{}( static_cast<int>( pad->GetShape() ) );
|
||||
hash_combine( ret, pad->GetDrillShape() );
|
||||
hash_combine( ret, pad->GetSize().x, pad->GetSize().y );
|
||||
hash_combine( ret, pad->GetOffset().x, pad->GetOffset().y );
|
||||
hash_combine( ret, pad->GetDelta().x, pad->GetDelta().y );
|
||||
|
||||
hash_combine( ret, hash_board_item( pad, aFlags ) );
|
||||
|
||||
|
|
|
@ -60,32 +60,4 @@ enum HASH_FLAGS
|
|||
*/
|
||||
std::size_t hash_fp_item( const EDA_ITEM* aItem, int aFlags = HASH_FLAGS::HASH_ALL );
|
||||
|
||||
/**
|
||||
* This is a dummy function to take the final case of hash_combine below
|
||||
* @param seed
|
||||
*/
|
||||
static inline void hash_combine( std::size_t &seed ) {}
|
||||
|
||||
/**
|
||||
* Combine multiple hashes utilizing previous hash result.
|
||||
*
|
||||
* @tparam T A hashable type
|
||||
* @param seed A seed value input and output for the result.
|
||||
* @param val A hashable object of type T
|
||||
*/
|
||||
template< typename T, typename ... Types >
|
||||
static inline void hash_combine( std::size_t &seed, const T &val, const Types &... args )
|
||||
{
|
||||
seed ^= std::hash<T>()( val ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
|
||||
hash_combine( seed, args... );
|
||||
}
|
||||
|
||||
template <typename... Types>
|
||||
static inline std::size_t hash_val( const Types &... args )
|
||||
{
|
||||
std::size_t seed = 0xa82de1c0;
|
||||
hash_combine( seed, args... );
|
||||
return seed;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 KiCad Developers, see CHANGELOG.TXT for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 3 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef LIBS_KIMATH_INCLUDE_HASH_H_
|
||||
#define LIBS_KIMATH_INCLUDE_HASH_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* This is a dummy function to take the final case of hash_combine below
|
||||
* @param seed
|
||||
*/
|
||||
static inline void hash_combine( std::size_t &seed ) {}
|
||||
|
||||
/**
|
||||
* Combine multiple hashes utilizing previous hash result.
|
||||
*
|
||||
* @tparam T A hashable type
|
||||
* @param seed A seed value input and output for the result.
|
||||
* @param val A hashable object of type T
|
||||
*/
|
||||
template< typename T, typename ... Types >
|
||||
static inline void hash_combine( std::size_t &seed, const T &val, const Types &... args )
|
||||
{
|
||||
seed ^= std::hash<T>()( val ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
|
||||
hash_combine( seed, args... );
|
||||
}
|
||||
|
||||
template <typename... Types>
|
||||
static inline std::size_t hash_val( const Types &... args )
|
||||
{
|
||||
std::size_t seed = 0xa82de1c0;
|
||||
hash_combine( seed, args... );
|
||||
return seed;
|
||||
}
|
||||
|
||||
#endif /* LIBS_KIMATH_INCLUDE_HASH_H_ */
|
|
@ -53,6 +53,7 @@
|
|||
#include <math/util.h> // for KiROUND, rescale
|
||||
#include <math/vector2d.h> // for VECTOR2I, VECTOR2D, VECTOR2
|
||||
#include <md5_hash.h>
|
||||
#include <hash.h>
|
||||
#include <geometry/shape_segment.h>
|
||||
#include <geometry/shape_circle.h>
|
||||
|
||||
|
@ -1122,8 +1123,9 @@ void SHAPE_POLY_SET::unfractureSingle( SHAPE_POLY_SET::POLYGON& aPoly )
|
|||
std::size_t operator()( const EDGE& aEdge ) const
|
||||
{
|
||||
const SEG& a = aEdge.m_poly->CSegment( aEdge.m_index );
|
||||
|
||||
return (std::size_t) ( a.A.x + a.B.x + a.A.y + a.B.y );
|
||||
std::size_t seed = 0xa82de1c0;
|
||||
hash_combine( seed, a.A.x, a.B.x, a.A.y, a.B.y );
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <board_item_container.h>
|
||||
#include <common.h> // Needed for stl hash extensions
|
||||
#include <convert_shape_list_to_polygon.h> // for OUTLINE_ERROR_HANDLER
|
||||
#include <hash.h>
|
||||
#include <layer_ids.h>
|
||||
#include <netinfo.h>
|
||||
#include <pcb_item_containers.h>
|
||||
|
@ -105,10 +106,9 @@ namespace std
|
|||
{
|
||||
std::size_t operator()( const PTR_PTR_CACHE_KEY& k ) const
|
||||
{
|
||||
constexpr std::size_t prime = 2166136261u;
|
||||
|
||||
return reinterpret_cast<uintptr_t>( k.A ) * prime
|
||||
^ reinterpret_cast<uintptr_t>( k.B ) * prime;
|
||||
std::size_t seed = 0xa82de1c0;
|
||||
hash_combine( seed, k.A, k.B );
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -117,10 +117,9 @@ namespace std
|
|||
{
|
||||
std::size_t operator()( const PTR_LAYER_CACHE_KEY& k ) const
|
||||
{
|
||||
constexpr std::size_t prime = 2166136261u;
|
||||
|
||||
return reinterpret_cast<uintptr_t>( k.A ) * prime
|
||||
^ hash<int>()( k.Layer ) * prime;
|
||||
std::size_t seed = 0xa82de1c0;
|
||||
hash_combine( seed, k.A, k.Layer );
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -129,11 +128,9 @@ namespace std
|
|||
{
|
||||
std::size_t operator()( const PTR_PTR_LAYER_CACHE_KEY& k ) const
|
||||
{
|
||||
constexpr std::size_t prime = 2166136261u;
|
||||
|
||||
return reinterpret_cast<uintptr_t>( k.A ) * prime
|
||||
^ reinterpret_cast<uintptr_t>( k.B ) * prime
|
||||
^ hash<int>()( k.Layer ) * prime;
|
||||
std::size_t seed = 0xa82de1c0;
|
||||
hash_combine( seed, k.A, k.B, k.Layer );
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#ifndef __PCB_EDIT_FRAME_H__
|
||||
#define __PCB_EDIT_FRAME_H__
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include "pcb_base_edit_frame.h"
|
||||
#include "zones.h"
|
||||
#include <mail_type.h>
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include <eda_text.h>
|
||||
#include <geometry/shape_arc.h>
|
||||
#include <hash_eda.h>
|
||||
#include <pad_shapes.h>
|
||||
|
||||
#include <deque>
|
||||
|
|
Loading…
Reference in New Issue