diff options
author | Chris Lattner <sabre@nondot.org> | 2007-02-11 19:49:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-02-11 19:49:41 +0000 |
commit | b5bb9f5b5cfe89f4b7626671f4923d50f8d4cd6a (patch) | |
tree | d3d3bd107a464a4c735be79fa6544855555d4c7d /include/llvm | |
parent | ea7acb859111a7f55c497e0b7cf569ac81e97208 (diff) | |
download | external_llvm-b5bb9f5b5cfe89f4b7626671f4923d50f8d4cd6a.tar.gz external_llvm-b5bb9f5b5cfe89f4b7626671f4923d50f8d4cd6a.tar.bz2 external_llvm-b5bb9f5b5cfe89f4b7626671f4923d50f8d4cd6a.zip |
Replace the ugly FindValue method with STL-like find methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34183 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/ADT/StringMap.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 52982589f7..7cc9ce7b6c 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -64,6 +64,11 @@ protected: /// of the string. unsigned LookupBucketFor(const char *KeyStart, const char *KeyEnd); + /// FindKey - Look up the bucket that contains the specified key. If it exists + /// in the map, return the bucket number of the key. Otherwise return -1. + /// This does not modify the map. + int FindKey(const char *KeyStart, const char *KeyEnd) const; + public: static StringMapEntryBase *getTombstoneVal() { return (StringMapEntryBase*)-1; @@ -175,11 +180,17 @@ public: const_iterator begin() const { return const_iterator(TheTable); } const_iterator end() const { return const_iterator(TheTable+NumBuckets); } - /// FindValue - Look up the specified key in the map. If it exists, return a - /// pointer to the element, otherwise return null. - MapEntryTy *FindValue(const char *KeyStart, const char *KeyEnd) { - unsigned BucketNo = LookupBucketFor(KeyStart, KeyEnd); - return static_cast<MapEntryTy*>(TheTable[BucketNo].Item); + + iterator find(const char *KeyStart, const char *KeyEnd) { + int Bucket = FindKey(KeyStart, KeyEnd); + if (Bucket == -1) return end(); + return iterator(TheTable+Bucket); + } + + const_iterator find(const char *KeyStart, const char *KeyEnd) const { + int Bucket = FindKey(KeyStart, KeyEnd); + if (Bucket == -1) return end(); + return const_iterator(TheTable+Bucket); } /// GetOrCreateValue - Look up the specified key in the table. If a value |