mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 01:27:16 +08:00
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:
14
src/misc.h
14
src/misc.h
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user