Fix UtlHash for 64-bit.

This commit is contained in:
Nicholas Hastings 2016-11-09 15:21:21 -05:00
parent 90995ab9ec
commit 6e19ef7779

View File

@ -489,7 +489,7 @@ inline void CUtlHash<Data, C, K>::Dump( )
// Number of buckets must be a power of 2. // Number of buckets must be a power of 2.
// Key must be 32-bits (unsigned int). // Key must be 32-bits (unsigned int).
// //
typedef int UtlHashFastHandle_t; typedef intp UtlHashFastHandle_t;
#define UTLHASH_POOL_SCALAR 2 #define UTLHASH_POOL_SCALAR 2
@ -534,15 +534,15 @@ public:
// int Count( void ) const; // int Count( void ) const;
// Insertion. // Insertion.
UtlHashFastHandle_t Insert( unsigned int uiKey, const Data &data ); UtlHashFastHandle_t Insert( uintp uiKey, const Data &data );
UtlHashFastHandle_t FastInsert( unsigned int uiKey, const Data &data ); UtlHashFastHandle_t FastInsert( uintp uiKey, const Data &data );
// Removal. // Removal.
void Remove( UtlHashFastHandle_t hHash ); void Remove( UtlHashFastHandle_t hHash );
void RemoveAll( void ); void RemoveAll( void );
// Retrieval. // Retrieval.
UtlHashFastHandle_t Find( unsigned int uiKey ) const; UtlHashFastHandle_t Find( uintp uiKey ) const;
Data &Element( UtlHashFastHandle_t hHash ); Data &Element( UtlHashFastHandle_t hHash );
Data const &Element( UtlHashFastHandle_t hHash ) const; Data const &Element( UtlHashFastHandle_t hHash ) const;
@ -571,7 +571,7 @@ public:
template <typename HashData> template <typename HashData>
struct HashFastData_t_ struct HashFastData_t_
{ {
unsigned int m_uiKey; uintp m_uiKey;
HashData m_Data; HashData m_Data;
}; };
@ -650,7 +650,7 @@ template<class Data, class HashFuncs> inline int CUtlHashFast<Data,HashFuncs>::C
// Purpose: Insert data into the hash table given its key (unsigned int), with // Purpose: Insert data into the hash table given its key (unsigned int), with
// a check to see if the element already exists within the tree. // a check to see if the element already exists within the tree.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::Insert( unsigned int uiKey, const Data &data ) template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::Insert( uintp uiKey, const Data &data )
{ {
// Check to see if that key already exists in the buckets (should be unique). // Check to see if that key already exists in the buckets (should be unique).
UtlHashFastHandle_t hHash = Find( uiKey ); UtlHashFastHandle_t hHash = Find( uiKey );
@ -664,10 +664,10 @@ template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Da
// Purpose: Insert data into the hash table given its key (unsigned int), // Purpose: Insert data into the hash table given its key (unsigned int),
// without a check to see if the element already exists within the tree. // without a check to see if the element already exists within the tree.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::FastInsert( unsigned int uiKey, const Data &data ) template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::FastInsert( uintp uiKey, const Data &data )
{ {
// Get a new element from the pool. // Get a new element from the pool.
int iHashData = m_aDataPool.Alloc( true ); intp iHashData = m_aDataPool.Alloc( true );
HashFastData_t *pHashData = &m_aDataPool[iHashData]; HashFastData_t *pHashData = &m_aDataPool[iHashData];
if ( !pHashData ) if ( !pHashData )
return InvalidHandle(); return InvalidHandle();
@ -716,12 +716,12 @@ template<class Data, class HashFuncs> inline void CUtlHashFast<Data,HashFuncs>::
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::Find( unsigned int uiKey ) const template<class Data, class HashFuncs> inline UtlHashFastHandle_t CUtlHashFast<Data,HashFuncs>::Find( uintp uiKey ) const
{ {
// hash the "key" - get the correct hash table "bucket" // hash the "key" - get the correct hash table "bucket"
int iBucket = HashFuncs::Hash( uiKey, m_uiBucketMask ); int iBucket = HashFuncs::Hash( uiKey, m_uiBucketMask );
for ( int iElement = m_aBuckets[iBucket]; iElement != m_aDataPool.InvalidIndex(); iElement = m_aDataPool.Next( iElement ) ) for ( intp iElement = m_aBuckets[iBucket]; iElement != m_aDataPool.InvalidIndex(); iElement = m_aDataPool.Next( iElement ) )
{ {
if ( m_aDataPool[iElement].m_uiKey == uiKey ) if ( m_aDataPool[iElement].m_uiKey == uiKey )
return iElement; return iElement;
@ -832,7 +832,7 @@ template<class Data, class HashFuncs> inline bool CUtlHashFast<Data,HashFuncs>::
// Number of buckets must be a power of 2. // Number of buckets must be a power of 2.
// Key must be 32-bits (unsigned int). // Key must be 32-bits (unsigned int).
// //
typedef int UtlHashFixedHandle_t; typedef intp UtlHashFixedHandle_t;
template <int NUM_BUCKETS> template <int NUM_BUCKETS>
class CUtlHashFixedGenericHash class CUtlHashFixedGenericHash