996
|
1 /*********************************************************************
|
|
2 *
|
|
3 * Copyright (C) 2001-2005, Simon Kagstrom
|
|
4 *
|
|
5 * Filename: hash_table.c
|
|
6 * Description: The implementation of the hash table (MK2).
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or
|
|
9 * modify it under the terms of the GNU Library General Public License
|
|
10 * as published by the Free Software Foundation; either version 2
|
|
11 * of the License, or (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU Library General Public
|
|
19 * License along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
21 * 02111-1307, USA.
|
|
22 *
|
|
23 * $Id: hash_table.c 15761 2007-07-15 06:08:52Z ska $
|
|
24 *
|
|
25 ********************************************************************/
|
|
26
|
|
27 #include <stdlib.h> /* malloc */
|
|
28 #include <stdio.h> /* perror */
|
|
29 #include <errno.h> /* errno */
|
|
30 #include <string.h> /* memcmp */
|
|
31 #include <stdbool.h>
|
|
32 #include <assert.h> /* assert */
|
|
33
|
|
34 #define CF_GHT_INTERNAL
|
|
35 #include "ght_hash_table.h"
|
|
36
|
|
37 #include "../../src/global.h"
|
|
38 #include "../../src/diagnostic.h"
|
|
39
|
|
40 #include "cfunge_mempool.h"
|
|
41
|
|
42 /* Flags for the elements. This is currently unused. */
|
|
43 #define FLAGS_NONE 0 /* No flags */
|
|
44 #define FLAGS_NORMAL 0 /* Normal item. All user-inserted stuff is normal */
|
|
45 #define FLAGS_INTERNAL 1 /* The item is internal to the hash table */
|
|
46
|
|
47 #define CF_GHT_VAR fspace
|
|
48 #define CF_GHT_KEY fungeSpaceHashKey
|
|
49 #define CF_GHT_DATA funge_cell
|
|
50 #define CF_GHT_COMPAREKEYS(m_a, m_b) (((m_a)->p_key.x == (m_b)->p_key.x) && ((m_a)->p_key.y == (m_b)->p_key.y))
|
|
51 #define CF_GHT_COPYKEY(m_target, m_source) \
|
|
52 do { \
|
|
53 (m_target).x = (m_source)->x; \
|
|
54 (m_target).y = (m_source)->y; \
|
|
55 } while (0)
|
|
56
|
|
57 #include "hash_table_priv.h"
|
|
58
|
|
59 #undef CF_GHT_VAR
|
|
60 #undef CF_GHT_KEY
|
|
61 #undef CF_GHT_DATA
|
|
62 #undef CF_GHT_COMPAREKEYS
|
|
63 #undef CF_GHT_COPYKEY
|
|
64
|
|
65 #ifdef CFUN_EXACT_BOUNDS
|
|
66 # define CF_GHT_VAR fspacecount
|
|
67 # define CF_GHT_KEY funge_cell
|
|
68 # define CF_GHT_DATA funge_unsigned_cell
|
|
69 # define CF_GHT_COMPAREKEYS(m_a, m_b) ((m_a)->p_key == (m_b)->p_key)
|
|
70 # define CF_GHT_COPYKEY(m_target, m_source) \
|
|
71 do { (m_target) = *(m_source); } while (0)
|
|
72
|
|
73 # include "hash_table_priv.h"
|
|
74 #endif
|