diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-11-01 00:54:57 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-11-01 00:54:57 +0000 |
commit | c2b097a16c78eeccec5ffd0f026c59c7fa11ba66 (patch) | |
tree | 2205a3748421fc6f0f117d46fc8b97f21bd3611c /include/llvm/ADT | |
parent | aa059b114dfee9e1c5b05d09371bdbbf4600fd10 (diff) | |
download | external_llvm-c2b097a16c78eeccec5ffd0f026c59c7fa11ba66.zip external_llvm-c2b097a16c78eeccec5ffd0f026c59c7fa11ba66.tar.gz external_llvm-c2b097a16c78eeccec5ffd0f026c59c7fa11ba66.tar.bz2 |
Added typedef "value_type" to DenseMap (similar typedef appears in std::map).
Added method FindAndConstruct() to DenseMap, which does the same thing as
operator[], except that it refers value_type& (a reference to both the
key and mapped data pair). This method is useful for clients that wish
to access the stored key value, as opposed to the key used to do the
actual lookup (these need not always be the same).
Redefined operator[] to use FindAndConstruct() (same logic).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43594 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/DenseMap.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 91f00f9..7f02dc9 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -63,6 +63,8 @@ class DenseMap { unsigned NumEntries; unsigned NumTombstones; public: + typedef BucketT value_type; + DenseMap(const DenseMap& other) { NumBuckets = 0; CopyFrom(other); @@ -174,13 +176,17 @@ public: ++NumTombstones; return true; } - - ValueT &operator[](const KeyT &Key) { + + value_type& FindAndConstruct(const KeyT &Key) { BucketT *TheBucket; if (LookupBucketFor(Key, TheBucket)) - return TheBucket->second; - - return InsertIntoBucket(Key, ValueT(), TheBucket)->second; + return *TheBucket; + + return *InsertIntoBucket(Key, ValueT(), TheBucket); + } + + ValueT &operator[](const KeyT &Key) { + return FindAndConstruct(Key).second; } DenseMap& operator=(const DenseMap& other) { |