Explorar o código

Add entries() to go with keys() for future use.

Adam Ierymenko %!s(int64=10) %!d(string=hai) anos
pai
achega
cfd101c9b8
Modificáronse 1 ficheiros con 20 adicións e 0 borrados
  1. 20 0
      node/Hashtable.hpp

+ 20 - 0
node/Hashtable.hpp

@@ -30,6 +30,8 @@
 
 #include <stdexcept>
 #include <vector>
+#include <utility>
+#include <algorithm>
 
 namespace ZeroTier {
 
@@ -196,6 +198,24 @@ public:
 		return k;
 	}
 
+	/**
+	 * @return Vector of all entries (pairs of K,V)
+	 */
+	inline typename std::vector< std::pair<K,V> > entries()
+	{
+		typename std::vector< std::pair<K,V> > k;
+		if (_s) {
+			for(unsigned long i=0;i<_bc;++i) {
+				_Bucket *b = _t[i];
+				while (b) {
+					k.push_back(std::pair<K,V>(b->k,b->v));
+					b = b->next;
+				}
+			}
+		}
+		return k;
+	}
+
 	/**
 	 * @param k Key
 	 * @return Pointer to value or NULL if not found