Use std::vector to implement HashTable

Allows some code semplification and avoids directly
allocation and managing heap memory.

Also the usual renaming while there.

No functional change and no speed regression.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2012-03-31 12:15:57 +01:00
parent 304deb5e83
commit 32c504076f
9 changed files with 83 additions and 110 deletions

View File

@@ -22,6 +22,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "types.h"
@@ -48,8 +49,7 @@ struct Log : public std::ofstream {
};
class Time {
public:
struct Time {
void restart() { system_time(&t); }
uint64_t msec() const { return time_to_msec(t); }
int elapsed() const { return int(current_time().msec() - time_to_msec(t)); }
@@ -60,4 +60,14 @@ private:
sys_time_t t;
};
template<class Entry, int Size>
struct HashTable {
HashTable() : e(Size, Entry()) { memset(&e[0], 0, sizeof(Entry) * Size); }
Entry* operator[](Key k) { return &e[(uint32_t)k & (Size - 1)]; }
private:
std::vector<Entry> e;
};
#endif // !defined(MISC_H_INCLUDED)