aboutsummaryrefslogtreecommitdiff
path: root/include/tt.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/tt.c')
-rw-r--r--include/tt.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/include/tt.c b/include/tt.c
index b1f583e..8ad6c56 100644
--- a/include/tt.c
+++ b/include/tt.c
@@ -43,18 +43,28 @@ tt_entry_t *tt_seek(const uint64_t key) {
return NULL;
}
-int tt_insert(const uint64_t key, const enum TT_FLAG flag,
- const uint8_t depth, const float value,
- const action_t action) {
+tt_entry_t *tt_store(const uint64_t key, const enum TT_FLAG flag,
+ const uint8_t depth, const float value,
+ const action_t action) {
tt_entry_t *e = &table[key & TT_SIZE];
- // Replacement scheme: keep a stale-but-deeper entry over a shallower new one.
+ if (e->gen == tt_gen && e->key == key) {
+ // The slot holds this very position: update it (gen and key are already
+ // correct).
+ e->flag = flag;
+ e->value = value;
+ e->depth = depth;
+ e->action = action;
+ return e;
+ }
+ // Empty slot, stale generation, or a different position: keep a deeper search
+ // of a foreign position over this shallower one.
if (e->gen == tt_gen && e->depth > depth)
- return EXIT_SUCCESS;
+ return NULL;
e->key = key;
e->value = value;
e->action = action;
e->gen = tt_gen;
e->flag = flag;
e->depth = depth;
- return EXIT_SUCCESS;
+ return e;
}