]> git.llucax.com Git - z.facultad/75.52/treemulator.git/commitdiff
Agrego KeyManager.
authorRicardo Markiewicz <rmarkie@fi.uba.ar>
Mon, 24 Oct 2005 06:13:57 +0000 (06:13 +0000)
committerRicardo Markiewicz <rmarkie@fi.uba.ar>
Mon, 24 Oct 2005 06:13:57 +0000 (06:13 +0000)
src/keymanager.h [new file with mode: 0644]

diff --git a/src/keymanager.h b/src/keymanager.h
new file mode 100644 (file)
index 0000000..d457fcb
--- /dev/null
@@ -0,0 +1,56 @@
+
+#ifndef _KEY_MANAGER_H_
+#define _KEY_MANAGER_H_
+
+#include <list>
+#include "random.h"
+
+template <class T>
+class KeyManager {
+       public:
+               KeyManager ()
+               {
+                       altas = 0;
+                       bajas = 0;
+               }
+
+               void AddValue (T k)
+               {
+                       keys.push_back (k);
+                       altas ++;
+               }
+
+               T GetRandom ()
+               {
+                       int l = 0;
+                       int n = (int)Random::Double (0, keys.size ());
+
+                       typename std::list< T >::iterator it = keys.begin ();
+                       while (l < n) {
+                               l++;
+                               it++;
+                       }
+
+                       T ret = (*it);
+
+                       keys.erase (it);
+
+                       bajas ++;
+                       return ret;
+               }
+
+               void PrintInfo ()
+               {
+                       std::cout << "Cantidad de Altas : " << altas << std::endl;
+                       std::cout << "Cantidad de Bajas : " << bajas << std::endl;
+               }
+
+               std::list < T >& GetList () { return keys; }
+       private:
+               std::list< T > keys;
+               int altas;
+               int bajas;
+};
+
+#endif
+