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

@@ -20,12 +20,9 @@
#if !defined(TT_H_INCLUDED)
#define TT_H_INCLUDED
#include <iostream>
#include "misc.h"
#include "types.h"
/// The TTEntry is the class of transposition table entries
///
/// A TTEntry needs 128 bits to be stored
@@ -136,35 +133,4 @@ inline void TranspositionTable::refresh(const TTEntry* tte) const {
const_cast<TTEntry*>(tte)->set_generation(generation);
}
/// A simple hash table used to store pawns and material configurations. It is
/// basically just an array of Entry objects. Without cluster concept, overwrite
/// policy nor resizing.
template<class Entry, int HashSize>
struct HashTable {
typedef HashTable<Entry, HashSize> Base;
HashTable() {
entries = new (std::nothrow) Entry[HashSize];
if (!entries)
{
std::cerr << "Failed to allocate " << HashSize * sizeof(Entry)
<< " bytes for hash table." << std::endl;
::exit(EXIT_FAILURE);
}
memset(entries, 0, HashSize * sizeof(Entry));
}
virtual ~HashTable() { delete [] entries; }
Entry* probe(Key key) const { return entries + ((uint32_t)key & (HashSize - 1)); }
void prefetch(Key key) const { ::prefetch((char*)probe(key)); }
private:
Entry* entries;
};
#endif // !defined(TT_H_INCLUDED)