File: hashtable.h

package info (click to toggle)
sjaakii 1.4.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,628 kB
  • sloc: ansic: 16,287; cpp: 4,543; makefile: 15
file content (64 lines) | stat: -rw-r--r-- 2,339 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*  Jazz, a program for playing chess
 *  Copyright (C) 2009, 2011  Evert Glebbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef HASHTABLE_H
#define HASHTABLE_H

#include <stdint.h>
#include "move.h"

/* Types of entries that may occur in the table (flags) */
#define HASH_TYPE_EXACT       0x00000001
#define HASH_TYPE_LOWER       0x00000002
#define HASH_TYPE_UPPER       0x00000004

#ifdef __cplusplus
extern "C" {
#endif

/* Entries in the hash table */
typedef struct {
   uint32_t lock;          /* Store the full key (for position verification) */
   move_t best_move;       /* The best move returned from the previous search */
   int16_t score;          /* The value of this node */
   int16_t depth;          /* The depth to which this position was searched; distance from horizon */
   uint8_t flags;          /* Properties of this entry */
   uint8_t generation;     /* Generation of this entry */
} hash_table_entry_t;

typedef struct {
   /* We keep two parallel hash tables: a "depth priority" table and an
    * "always replace" table.
    */
   hash_table_entry_t *data;
   size_t number_of_elements;
   size_t write_count;
   uint8_t generation;
} hash_table_t;

hash_table_t *create_hash_table(size_t nelem);
void destroy_hash_table(hash_table_t *table);
void store_table_entry(hash_table_t *table, uint64_t key, int depth,  int score, unsigned int flags, move_t best_move);
bool retrieve_table(hash_table_t *table, uint64_t key, int *depth, int *score, unsigned int *flags, move_t *best_move);
void prefetch_hashtable(hash_table_t *table, uint64_t key);
void prepare_hashtable_search(hash_table_t *table);
int count_unused_table_entries(hash_table_t *table);

#ifdef __cplusplus
}
#endif

#endif