X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bfe1edbddba7ab2ffc59d0d13252dfc03d609bd6..bc94d944d0ebde1599e820e5bb68a13d56adc1a9:/include/wx/hashmap.h diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index ad8005c31c..41aaccb230 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: hashmap.h +// Name: wx/hashmap.h // Purpose: wxHashMap class // Author: Mattia Barbon // Modified by: @@ -34,7 +34,7 @@ #endif #define _WX_DECLARE_HASH_MAP( KEY_T, VALUE_T, HASH_T, KEY_EQ_T, CLASSNAME, CLASSEXP ) \ - typedef WX_HASH_MAP_NAMESPACE::hash_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME; + typedef WX_HASH_MAP_NAMESPACE::hash_map< KEY_T, VALUE_T, HASH_T, KEY_EQ_T > CLASSNAME #else // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP) @@ -202,6 +202,7 @@ public: \ { \ public: \ const_iterator() : Iterator() {} \ + const_iterator(iterator i) : Iterator(i) {} \ const_iterator( Node* node, const Self* ht ) \ : Iterator( node, (Self*)ht ) {} \ const_iterator& operator++() { PlusPlus();return *this; } \ @@ -337,25 +338,26 @@ protected: \ /* returns NULL if not found */ \ Node** GetNodePtr( const const_key_type& key ) const \ { \ - unsigned long hash = wx_static_cast(unsigned long, m_hasher( key )); \ - Node** node = &m_table[hash % m_tableBuckets]; \ + size_t bucket = m_hasher( key ) % m_tableBuckets; \ + Node** node = &m_table[bucket]; \ \ while( *node ) \ { \ if( m_equals( m_getKey( (*node)->m_value ), key ) ) \ return node; \ + /* Tell the compiler to not do any strict-aliasing assumptions with a void cast? Can we make such a runtime guarantee? */ \ node = (Node**)&(*node)->m_nxt; \ } \ \ - return 0; \ + return NULL; \ } \ \ /* returns NULL if not found */ \ /* expressing it in terms of GetNodePtr is 5-8% slower :-( */ \ Node* GetNode( const const_key_type& key ) const \ { \ - unsigned long hash = wx_static_cast(unsigned long, m_hasher( key )); \ - Node* node = m_table[hash % m_tableBuckets]; \ + size_t bucket = m_hasher( key ) % m_tableBuckets; \ + Node* node = m_table[bucket]; \ \ while( node ) \ { \ @@ -462,11 +464,21 @@ class WXDLLIMPEXP_BASE wxIntegerHash WX_HASH_MAP_NAMESPACE::hash shortHash; WX_HASH_MAP_NAMESPACE::hash ushortHash; +#if defined wxLongLong_t && !defined wxLongLongIsLong + // hash ought to work but doesn't on some compilers + #if (!defined SIZEOF_LONG_LONG && SIZEOF_LONG == 4) \ + || (defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG * 2) size_t longlongHash( wxLongLong_t x ) const { return longHash( wx_truncate_cast(long, x) ) ^ longHash( wx_truncate_cast(long, x >> (sizeof(long) * 8)) ); } + #elif defined SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_LONG + WX_HASH_MAP_NAMESPACE::hash longlongHash; + #else + WX_HASH_MAP_NAMESPACE::hash longlongHash; + #endif +#endif public: wxIntegerHash() { } @@ -637,7 +649,10 @@ public: \ \ /* count() == 0 | 1 */ \ size_type count( const const_key_type& key ) \ - { return GetNode( key ) ? 1 : 0; } \ + { \ + /* explicit cast needed to suppress CodeWarrior warnings */ \ + return (size_type)(GetNode( key ) ? 1 : 0); \ + } \ } #endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP) @@ -701,4 +716,3 @@ WX_DECLARE_HASH_MAP_WITH_DECL( long, long, wxIntegerHash, wxIntegerEqual, #endif // _WX_HASHMAP_H_ -