From 213408b5a596597ff3493a8966d585218f8d63ad Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 24 Oct 2005 06:13:57 +0000 Subject: [PATCH] Agrego KeyManager. --- src/keymanager.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/keymanager.h diff --git a/src/keymanager.h b/src/keymanager.h new file mode 100644 index 0000000..d457fcb --- /dev/null +++ b/src/keymanager.h @@ -0,0 +1,56 @@ + +#ifndef _KEY_MANAGER_H_ +#define _KEY_MANAGER_H_ + +#include +#include "random.h" + +template +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 + -- 2.43.0