summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@google.com>2018-12-05 15:31:20 -0800
committerYong He <yonghe@google.com>2018-12-13 11:44:31 -0800
commit8d13c06ab51f4993f5c56772e83fba3c384674df (patch)
tree98897b8ace1b2beef993903b96fdf0c79046c460
parent76280cfc114e489f4b596dc2b0e2a560b7f13a55 (diff)
Fix dictionary performance issue
-rw-r--r--source/core/dictionary.h10
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;