Autotune Framework
[satune.git] / src / Collections / hashset.h
index 6a823f5c58643f142c0397db13141cdae4f9f4f4..c86217cc8033cb3c20b045340317c236337a0972 100644 (file)
@@ -148,6 +148,23 @@ public:
                        return false;
        }
 
+  /** @brief Return random key from set. */
+
+  _Key getRandomElement() {
+               if (getSize() == 0)
+                       return NULL;
+               else if (getSize() < 6) {
+                       uint count = random() % getSize();
+                       LinkNode<_Key> *ptr=list;
+                       while(count > 0) {
+                               ptr = ptr->next;
+                               count--;
+                       }
+                       return ptr->key;
+               } else
+                       return table->getRandomValue()->key;
+       }
+
        /** @brief Gets the original key corresponding to this one from the
         *  hashset.  Returns NULL if not present. */