add support for iterators.
authorChris Lattner <sabre@nondot.org>
Sun, 11 Feb 2007 08:20:35 +0000 (08:20 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 11 Feb 2007 08:20:35 +0000 (08:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34179 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/StringMap.cpp

index 6eefd44c52fb933af385593c2ece80397af5eb9c..d56d1da6647ce957d4069f67f26319f4fabf5409 100644 (file)
@@ -25,8 +25,12 @@ StringMapImpl::StringMapImpl(unsigned InitSize, unsigned itemSize) {
   ItemSize = itemSize;
   NumItems = 0;
   
-  TheTable = new ItemBucket[NumBuckets]();
+  TheTable = new ItemBucket[NumBuckets+1]();
   memset(TheTable, 0, NumBuckets*sizeof(ItemBucket));
+  
+  // Allocate one extra bucket, set it to look filled so the iterators stop at
+  // end.
+  TheTable[NumBuckets].Item = (StringMapEntryBase*)2;
 }
 
 
@@ -94,8 +98,11 @@ unsigned StringMapImpl::LookupBucketFor(const char *NameStart,
 /// the appropriate mod-of-hashtable-size.
 void StringMapImpl::RehashTable() {
   unsigned NewSize = NumBuckets*2;
-  ItemBucket *NewTableArray = new ItemBucket[NewSize]();
+  // Allocate one extra bucket which will always be non-empty.  This allows the
+  // iterators to stop at end.
+  ItemBucket *NewTableArray = new ItemBucket[NewSize+1]();
   memset(NewTableArray, 0, NewSize*sizeof(ItemBucket));
+  NewTableArray[NewSize].Item = (StringMapEntryBase*)2;
   
   // Rehash all the items into their new buckets.  Luckily :) we already have
   // the hash values available, so we don't have to rehash any strings.