Add ImmutableMap::getMaxElement(), a method that returns the <key,value> pair in...
authorTed Kremenek <kremenek@apple.com>
Mon, 23 Feb 2009 17:27:18 +0000 (17:27 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 23 Feb 2009 17:27:18 +0000 (17:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65326 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/ImmutableMap.h
include/llvm/ADT/ImmutableSet.h

index 07cdb56a9ab0c08de4c5a27b6ac548f6c92ed4c4..00d59028aa07a04bc34c654ca7c485d8f2814ac1 100644 (file)
@@ -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.
index ba1262b077c31f1724ebf8a6fa79a207609bdef1..be274dbe6758ce18fbdfb540c187996fee0536df 100644 (file)
@@ -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.