From: Ted Kremenek Date: Mon, 23 Feb 2009 17:27:18 +0000 (+0000) Subject: Add ImmutableMap::getMaxElement(), a method that returns the pair in... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1c7a666fcef22e75dc675b06444f5a894f54d7be;p=oota-llvm.git Add ImmutableMap::getMaxElement(), a method that returns the 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 --- diff --git a/include/llvm/ADT/ImmutableMap.h b/include/llvm/ADT/ImmutableMap.h index 07cdb56a9ab..00d59028aa0 100644 --- a/include/llvm/ADT/ImmutableMap.h +++ b/include/llvm/ADT/ImmutableMap.h @@ -202,6 +202,13 @@ public: return 0; } + + /// getMaxElement - Returns the 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 ba1262b077c..be274dbe675 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.