diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-02-23 17:27:18 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-02-23 17:27:18 +0000 |
commit | 1c7a666fcef22e75dc675b06444f5a894f54d7be (patch) | |
tree | 90c4ff8ee69fd5f82d5da3990050c96c09210365 /include/llvm/ADT | |
parent | e2abdd3ff0dd54a59edbd114ebb1d7728040a2d9 (diff) | |
download | external_llvm-1c7a666fcef22e75dc675b06444f5a894f54d7be.zip external_llvm-1c7a666fcef22e75dc675b06444f5a894f54d7be.tar.gz external_llvm-1c7a666fcef22e75dc675b06444f5a894f54d7be.tar.bz2 |
Add ImmutableMap::getMaxElement(), a method that returns the <key,value> pair in a ImmutableMap that has the highest ranked key.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65326 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/ImmutableMap.h | 7 | ||||
-rw-r--r-- | include/llvm/ADT/ImmutableSet.h | 9 |
2 files changed, 16 insertions, 0 deletions
diff --git a/include/llvm/ADT/ImmutableMap.h b/include/llvm/ADT/ImmutableMap.h index 07cdb56..00d5902 100644 --- a/include/llvm/ADT/ImmutableMap.h +++ b/include/llvm/ADT/ImmutableMap.h @@ -202,6 +202,13 @@ public: return 0; } + + /// getMaxElement - Returns the <key,value> pair in the ImmutableMap for + /// which key is the highest in the ordering of keys in the map. This + /// method returns NULL if the map is empty. + value_type* getMaxElement() const { + return Root ? &(Root->getMaxElement()) : 0; + } //===--------------------------------------------------===// // Utility methods. diff --git a/include/llvm/ADT/ImmutableSet.h b/include/llvm/ADT/ImmutableSet.h index ba1262b..be274db 100644 --- a/include/llvm/ADT/ImmutableSet.h +++ b/include/llvm/ADT/ImmutableSet.h @@ -86,6 +86,15 @@ public: return NULL; } + + /// getMaxElement - Find the subtree associated with the highest ranged + /// key value. + ImutAVLTree* getMaxElement() { + ImutAVLTree *T = this; + ImutAVLTree *Right = T->getRight(); + while (Right) { T = Right; Right = T->getRight(); } + return T; + } /// size - Returns the number of nodes in the tree, which includes /// both leaves and non-leaf nodes. |