1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9#ifndef SQL_HASH_H
10#define SQL_HASH_H
11
12/* sql_hash implementation
13 * used to optimize search in expression and statement lists
14 */
15
16#include "sql_mem.h"
17
18#define HASH_MIN_SIZE 4
19
20typedef int (*fkeyvalue) (void *data);
21
22typedef struct sql_hash_e {
23 int key;
24 void *value;
25 struct sql_hash_e *chain;
26} sql_hash_e;
27
28typedef struct sql_hash {
29 sql_allocator *sa;
30 int size; /* power of 2 */
31 sql_hash_e **buckets;
32 fkeyvalue key;
33} sql_hash;
34
35extern sql_hash *hash_new(sql_allocator *sa, int size, fkeyvalue key);
36extern sql_hash_e *hash_add(sql_hash *ht, int key, void *value);
37extern void hash_del(sql_hash *ht, int key, void *value);
38
39extern unsigned int hash_key(const char *n);
40
41#endif /* SQL_HASH_H */
42