#include <cassert>
#include <cstring>
+#include <iostream>
#include "tt.h"
size_t newSize = 1024;
- // Transposition table consists of clusters and
- // each cluster consists of ClusterSize number of TTEntries.
- // Each non-empty entry contains information of exactly one position.
- // newSize is the number of clusters we are going to allocate.
- while ((2 * newSize) * sizeof(TTCluster) <= (mbSize << 20))
+ // Transposition table consists of clusters and each cluster consists
+ // of ClusterSize number of TTEntries. Each non-empty entry contains
+ // information of exactly one position and newSize is the number of
+ // clusters we are going to allocate.
+ while (2ULL * newSize * sizeof(TTCluster) <= (mbSize << 20))
newSize *= 2;
- if (newSize != size)
+ if (newSize == size)
+ return;
+
+ size = newSize;
+ delete [] entries;
+ entries = new (std::nothrow) TTCluster[size];
+ if (!entries)
{
- size = newSize;
- delete [] entries;
- entries = new TTCluster[size];
- if (!entries)
- {
- std::cerr << "Failed to allocate " << mbSize
- << " MB for transposition table." << std::endl;
- exit(EXIT_FAILURE);
- }
- clear();
+ std::cerr << "Failed to allocate " << mbSize
+ << " MB for transposition table." << std::endl;
+ exit(EXIT_FAILURE);
}
+ clear();
}
tte = replace = first_entry(posKey);
for (int i = 0; i < ClusterSize; i++, tte++)
{
- if (!tte->key() || tte->key() == posKey32) // empty or overwrite old
+ if (!tte->key() || tte->key() == posKey32) // Empty or overwrite old
{
// Preserve any existing ttMove
if (m == MOVE_NONE)
return;
}
- if (i == 0) // Replacing first entry is default and already set before entering for-loop
+ // Replacing first entry is default and already set before entering for-loop
+ if (i == 0)
continue;
c1 = (replace->generation() == generation ? 2 : 0);