Debian Codegraph @

src/common/hashtable.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2000 Ross Combs ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #ifndef INCLUDED_HASHTABLE_TYPES
19 #define INCLUDED_HASHTABLE_TYPES
20
21 namespace pvpgn
22 {
23
24 #ifdef HASHTABLE_INTERNAL_ACCESS
25 struct hashtable; /* forward reference for t_entry */
26 #endif
27
28 #ifdef HASHTABLE_INTERNAL_ACCESS
29 typedef struct internentry
30 {
31 void * data;
32 struct internentry * next;
33 }
34 t_internentry;
35 #endif
36
37 typedef struct entry
38 #ifdef HASHTABLE_INTERNAL_ACCESS
39 {
40 unsigned int row;
41 t_internentry * real;
42 struct hashtable const * hashtable;
43 }
44 #endif
45 t_entry;
46
47 typedef struct hashtable
48 #ifdef HASHTABLE_INTERNAL_ACCESS
49 {
50 unsigned int num_rows;
51 unsigned int len;
52 unsigned int zombies;
53 t_internentry * * rows;
54 }
55 #endif
56 t_hashtable;
57
58 }
59
60 #endif
61
62
63 /*****/
64 #ifndef JUST_NEED_TYPES
65 #ifndef INCLUDED_HASHTABLE_PROTOS
66 #define INCLUDED_HASHTABLE_PROTOS
67
68 namespace pvpgn
69 {
70
71 extern t_hashtable * hashtable_create(unsigned int num_rows);
72 extern int hashtable_destroy(t_hashtable * hashtable);
73 extern int hashtable_purge(t_hashtable * hashtable);
74 extern int hashtable_check(t_hashtable const * hashtable);
75 extern unsigned int hashtable_get_length(t_hashtable const * hashtable);
76 extern int hashtable_insert_data(t_hashtable * hashtable, void * data, unsigned int hash);
77 extern t_entry * hashtable_get_entry_by_data(t_hashtable const * hashtable, void const * data, unsigned int hash);
78 extern t_entry const * hashtable_get_entry_by_data_const(t_hashtable const * hashtable, void const * data, unsigned int hash);
79 extern int hashtable_remove_data(t_hashtable * hashtable, void const * data, unsigned int hash); /* delete matching item */
80 extern int hashtable_remove_entry(t_hashtable * hashtable, t_entry * entry);
81 extern void * hashtable_get_data_by_pos(t_hashtable const * hashtable, unsigned int pos);
82 extern void * entry_get_data(t_entry const * entry);
83 #ifdef HASHTABLE_DEBUG
84 extern t_entry * hashtable_match_get_first_real(t_hashtable const * hashtable, unsigned int hash, char const * fn, unsigned int ln);
85 # define hashtable_match_get_first(L,H) hashtable_match_get_first_real(L,H,__FILE__,__LINE__)
86 #else
87 extern t_entry * hashtable_match_get_first(t_hashtable const * hashtable, unsigned int hash);
88 #endif
89 extern t_entry * entry_match_get_next(t_entry const * entry, unsigned int hash);
90 #ifdef HASHTABLE_DEBUG
91 extern t_entry * hashtable_get_first_real(t_hashtable const * hashtable, char const * fn, unsigned int ln);
92 # define hashtable_get_first(L) hashtable_get_first_real(L,__FILE__,__LINE__)
93 #else
94 extern t_entry * hashtable_get_first(t_hashtable const * hashtable);
95 #endif
96 extern t_entry * entry_get_next(t_entry * entry);
97 #ifdef HASHTABLE_DEBUG
98 extern t_entry * hashtable_get_first_matching_real(t_hashtable const * hashtable, unsigned int hash, char const * fn, unsigned int ln);
99 # define hashtable_get_first_matching(L,H) hashtable_get_first_matching_real(L,H,__FILE__,__LINE__)
100 #else
101 extern t_entry * hashtable_get_first_matching(t_hashtable const * hashtable, unsigned int hash);
102 #endif
103 extern t_entry * entry_get_next_matching(t_entry * entry);
104 extern int hashtable_entry_release(t_entry * entry);
105 extern int hashtable_stats(t_hashtable * hashtable);
106
107 #define HASHTABLE_TRAVERSE(hashtable,curr) for (curr=hashtable_get_first(hashtable); curr; curr=entry_get_next(curr))
108 #define HASHTABLE_TRAVERSE_MATCHING(hashtable,curr,hash) for (curr=hashtable_get_first_matching(hashtable,hash); curr; curr=entry_get_next_matching(curr))
109
110 }
111
112 #endif
113 #endif