diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-05-26 13:53:10 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-26 13:53:10 -0400 |
| commit | b1369040c3d6d6a8704bdb17d9de99f36a108e07 (patch) | |
| tree | 2761b93946969fe2f505161d3c75e8cabb6107b6 /source/core/slang-dictionary.h | |
| parent | ee2ec68596262398b2d77c128f45b3f32a28c35e (diff) | |
Improvements around hashing (#1355)
* Fields from upper to lower case in slang-ast-decl.h
* Lower camel field names in slang-ast-stmt.h
* Fix fields in slang-ast-expr.h
* slang-ast-type.h make fields lowerCamel.
* slang-ast-base.h members functions lowerCamel.
* Method names in slang-ast-type.h to lowerCamel.
* GetCanonicalType -> getCanonicalType
* Substitute -> substitute
* Equals -> equals
ToString -> toString
* ParentDecl -> parentDecl
Members -> members
* * Make hash code types explicit
* Use HashCode as return type of GetHashCode
* Added conversion from double to int64_t
* Split Stable from other hash functions
* toHash32/64 to convert a HashCode to the other styles.
GetHashCode32/64 -> getHashCode32/64
GetStableHashCode32/64 -> getStableHashCode32/64
* Other Get/Stable/HashCode32/64 fixes
* GetHashCode -> getHashCode
* Equals -> equals
* CreateCanonicalType -> createCanonicalType
* Catches of polymorphic types should be through references otherwise slicing can occur.
* Fixes for newer verison of gcc.
Fix hashing problem on gcc for Dictionary.
* Another fix for GetHashPos
* Fix signed issue around GetHashPos
Diffstat (limited to 'source/core/slang-dictionary.h')
| -rw-r--r-- | source/core/slang-dictionary.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h index be7cc21f5..72b24f81c 100644 --- a/source/core/slang-dictionary.h +++ b/source/core/slang-dictionary.h @@ -54,11 +54,11 @@ namespace Slang Value = that.Value; return *this; } - int GetHashCode() + HashCode getHashCode() { return combineHash( - Slang::GetHashCode(Key), - Slang::GetHashCode(Value)); + Slang::getHashCode(Key), + Slang::getHashCode(Value)); } bool operator==(const KeyValuePair<TKey, TValue>& that) const { @@ -135,8 +135,10 @@ namespace Slang }; inline int GetHashPos(TKey& key) const - { - return ((unsigned int)(GetHashCode(key) * 2654435761)) % bucketSizeMinusOne; + { + SLANG_ASSERT(bucketSizeMinusOne > 0); + const unsigned int hash = (unsigned int)getHashCode(key); + return (hash * 2654435761u) % (unsigned int)(bucketSizeMinusOne); } FindPositionResult FindPosition(const TKey& key) const { @@ -166,7 +168,7 @@ namespace Slang } if (insertPos != -1) return FindPositionResult(-1, insertPos); - throw InvalidOperationException("Hash map is full. This indicates an error in Key::Equal or Key::GetHashCode."); + throw InvalidOperationException("Hash map is full. This indicates an error in Key::Equal or Key::getHashCode."); } TValue & _Insert(KeyValuePair<TKey, TValue>&& kvPair, int pos) { |
