[llvm-commits] CVS: llvm/include/llvm/ADT/StringMap.h
Chris Lattner
sabre at nondot.org
Sun Feb 11 11:50:01 PST 2007
Changes in directory llvm/include/llvm/ADT:
StringMap.h updated: 1.8 -> 1.9
---
Log message:
Replace the ugly FindValue method with STL-like find methods.
---
Diffs of the changes: (+16 -5)
StringMap.h | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
Index: llvm/include/llvm/ADT/StringMap.h
diff -u llvm/include/llvm/ADT/StringMap.h:1.8 llvm/include/llvm/ADT/StringMap.h:1.9
--- llvm/include/llvm/ADT/StringMap.h:1.8 Sun Feb 11 02:22:15 2007
+++ llvm/include/llvm/ADT/StringMap.h Sun Feb 11 13:49:41 2007
@@ -64,6 +64,11 @@
/// 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 @@
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
More information about the llvm-commits
mailing list