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 | e60504d2109656559e430b3e28dae9eecae9323f (patch) | |
| tree | 21008da375b91a04bf0008f1a17da3fe74ac10a9 | |
| parent | 1234749853d68a24cc0de6d7ce580fe05807341b (diff) | |
| download | bcm5719-llvm-e60504d2109656559e430b3e28dae9eecae9323f.tar.gz bcm5719-llvm-e60504d2109656559e430b3e28dae9eecae9323f.zip | |
Add ImmutableMap::getMaxElement(), a method that returns the <key,value> pair in a ImmutableMap that has the highest ranked key.
llvm-svn: 65326
| -rw-r--r-- | llvm/include/llvm/ADT/ImmutableMap.h | 7 | ||||
| -rw-r--r-- | llvm/include/llvm/ADT/ImmutableSet.h | 9 |
2 files changed, 16 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/ImmutableMap.h b/llvm/include/llvm/ADT/ImmutableMap.h index 07cdb56a9ab..00d59028aa0 100644 --- a/llvm/include/llvm/ADT/ImmutableMap.h +++ b/llvm/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/llvm/include/llvm/ADT/ImmutableSet.h b/llvm/include/llvm/ADT/ImmutableSet.h index ba1262b077c..be274dbe675 100644 --- a/llvm/include/llvm/ADT/ImmutableSet.h +++ b/llvm/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. |

