UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hashtable.h
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 /*
27  use:
28 
29  hashTable* t = HASH_NewTable ();
30 
31  HASH_Insert ("A1", 123);
32  HASH_Insert ("A2", 234);
33  HASH_Insert ("A3", 345);
34 
35 */
36 
37 #pragma once
38 
39 #ifndef HASHTABLE_H
40 #define HASHTABLE_H
41 
42 // forward declarations
43 struct memPool_t;
44 
46 struct hashTable_s;
47 
49 typedef unsigned short int HASH_INDEX;
51 typedef unsigned short int (*hashTable_hash) (const void* key, int len);
53 typedef int (*hashTable_compare) (const void* key1, int len1, const void* key2, int len2);
54 
59 void HASH_DeleteTable (hashTable_s** t);
60 
61 bool HASH_Insert (hashTable_s* t, const void* key, int nkey, const void* value, int nvalue);
62 void* HASH_Remove (hashTable_s* t, const void* key, int nkey);
63 void HASH_Clear (hashTable_s* t);
64 void* HASH_Get (hashTable_s* t, const void* key, int nkey);
65 int HASH_Count (hashTable_s* t);
66 
67 #ifdef __DEBUG__
68 bool HASH_test ();
69 #endif // __DEBUG__
70 
71 #endif // HASHTABLE_H
72 
73 
bool HASH_Insert(hashTable_s *t, const void *key, int nkey, const void *value, int nvalue)
Inserts a new value with given key into the hash table.
Definition: hashtable.cpp:369
bool duplicateOverwrite
Definition: hashtable.cpp:109
unsigned short int(* hashTable_hash)(const void *key, int len)
Definition: hashtable.h:51
void HASH_Clear(hashTable_s *t)
Clears the hash table.
Definition: hashtable.cpp:460
void * HASH_Remove(hashTable_s *t, const void *key, int nkey)
Removes an existing value with given key from the hash table.
Definition: hashtable.cpp:429
hashTable_s * HASH_NewTable(bool ownsKeys, bool ownsValues, bool duplicateOverwrite)
Creates a new hash table and sets it initial capacity.
Definition: hashtable.cpp:287
unsigned short int HASH_INDEX
Definition: hashtable.h:46
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
bool ownsValues
Definition: hashtable.cpp:106
hashBucket_s * table[HASH_TABLE_SIZE]
Definition: hashtable.cpp:98
The hash table structure, contains an array of buckets being indexed by the hash function.
Definition: hashtable.cpp:96
unsigned int key
Definition: cl_input.cpp:68
void * HASH_Get(hashTable_s *t, const void *key, int nkey)
Returns the value for a given key.
Definition: hashtable.cpp:467
void HASH_DeleteTable(hashTable_s **t)
Deletes a hash table and sets the pointer to NULL.
Definition: hashtable.cpp:351
QGL_EXTERN GLuint GLchar GLuint * len
Definition: r_gl.h:99
int(* hashTable_compare)(const void *key1, int len1, const void *key2, int len2)
Definition: hashtable.h:53
hashTable_s * HASH_CloneTable(hashTable_s *source)
Definition: hashtable.cpp:336
int HASH_Count(hashTable_s *t)
Returns the number of entries in the hash table.
Definition: hashtable.cpp:481