diff options
| author | Yong He <yonghe@outlook.com> | 2018-12-13 12:57:50 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-13 12:57:50 -0800 |
| commit | 765c87e83608b2987b3f15b4722d027f5f30f748 (patch) | |
| tree | cf57d89d6292d2f471c286b1b1c8d62d6b68bf84 | |
| parent | 822ed708364b257b7d2f61ecb8a51a4c96f7edaa (diff) | |
| parent | 970b58a209e06afc7bd104e4701abfbb055f7c4d (diff) | |
Merge pull request #755 from csyonghe/dictfix
Fix dictionary performance issue
| -rw-r--r-- | source/core/dictionary.h | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/source/core/dictionary.h b/source/core/dictionary.h index 408835454..d7daa1c6c 100644 --- a/source/core/dictionary.h +++ b/source/core/dictionary.h @@ -79,7 +79,7 @@ namespace Slang return 1; } private: - int bucketSizeMinusOne, shiftBits; + int bucketSizeMinusOne; int _count; IntSet marks; KeyValuePair<TKey, TValue>* hashMap; @@ -130,7 +130,7 @@ namespace Slang template<typename T> inline int GetHashPos(T & key) const { - return ((unsigned int)(GetHashCode(key) * 2654435761)) >> shiftBits; + return ((unsigned int)(GetHashCode(key) * 2654435761)) % bucketSizeMinusOne; } template<typename T> FindPositionResult FindPosition(const T & key) const @@ -175,14 +175,11 @@ namespace Slang if (bucketSizeMinusOne == -1 || _count / (float)bucketSizeMinusOne >= MaxLoadFactor) { int newSize = (bucketSizeMinusOne + 1) * 2; - int newShiftBits = shiftBits - 1; if (newSize == 0) { newSize = 16; - newShiftBits = 28; } Dictionary<TKey, TValue> newDict; - newDict.shiftBits = newShiftBits; newDict.bucketSizeMinusOne = newSize - 1; newDict.hashMap = new KeyValuePair<TKey, TValue>[newSize]; newDict.marks.SetMax(newSize * 2); @@ -433,7 +430,6 @@ namespace Slang Dictionary() { bucketSizeMinusOne = -1; - shiftBits = 32; _count = 0; hashMap = 0; } @@ -459,7 +455,6 @@ namespace Slang Free(); bucketSizeMinusOne = other.bucketSizeMinusOne; _count = other._count; - shiftBits = other.shiftBits; hashMap = new KeyValuePair<TKey, TValue>[other.bucketSizeMinusOne + 1]; marks = other.marks; for (int i = 0; i <= bucketSizeMinusOne; i++) @@ -474,7 +469,6 @@ namespace Slang bucketSizeMinusOne = other.bucketSizeMinusOne; _count = other._count; hashMap = other.hashMap; - shiftBits = other.shiftBits; marks = _Move(other.marks); other.hashMap = 0; other._count = 0; |
