aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-11 21:07:36 +0000
committerChris Lattner <sabre@nondot.org>2007-02-11 21:07:36 +0000
commit65033ffc297ce5610af9eedd38dc074e02dbff9b (patch)
tree6b9e444c5894d1fb7e38ab5c2d78c7d3ee45df7a
parent44dcd01cb3424420d79d5811fa8c1c052411f975 (diff)
do not allow hash table to be filled with tombstones.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34186 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/StringMap.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h
index 243f9cd13f..0c6b76d552 100644
--- a/include/llvm/ADT/StringMap.h
+++ b/include/llvm/ADT/StringMap.h
@@ -218,8 +218,11 @@ public:
Bucket.Item = KeyValue;
++NumItems;
- // If the hash table is now more than 3/4 full, rehash into a larger table.
- if (NumItems > NumBuckets*3/4)
+ // If the hash table is now more than 3/4 full, or if fewer than 1/8 of
+ // the buckets are empty (meaning that many are filled with tombstones),
+ // grow the table.
+ if (NumItems*4 > NumBuckets*3 ||
+ NumBuckets-(NumItems+NumTombstones) < NumBuckets/8)
RehashTable();
return true;
}
@@ -244,8 +247,11 @@ public:
// filled in by LookupBucketFor.
Bucket.Item = NewItem;
- // If the hash table is now more than 3/4 full, rehash into a larger table.
- if (NumItems > NumBuckets*3/4)
+ // If the hash table is now more than 3/4 full, or if fewer than 1/8 of
+ // the buckets are empty (meaning that many are filled with tombstones),
+ // grow the table.
+ if (NumItems*4 > NumBuckets*3 ||
+ NumBuckets-(NumItems+NumTombstones) < NumBuckets/8)
RehashTable();
return *NewItem;
}