Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
hashtab.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Westwood Library *
24 * *
25 * $Archive:: /Commando/Code/Library/hashtab.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 7/30/98 10:07a $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#ifndef HASHTAB_H
38#define HASHTAB_H
39
40#if 0
41
42template <class Object,class Key> class NamedObjectHashTableClass
43{
44
45public:
46
47 HashTableClass(int initialsize,int growthrate,HashCalculatorClass<Key> * hasher);
48 ~HashTableClass(void);
49
50 void Add(Object * new_item,Key * key);
51 void Remove(Object * item,Key * key);
52
53 int Count(void) const { return Items.Count(); }
54 Object * Find(const Key & key) const
55
56private:
57
58 enum { NO_ITEM = 0xFFFFFFFF };
59
60 class HashItem
61 {
62 public:
63 T * Item;
64 int NextHashIndex;
65
66 bool operator == (const HashItem & that) { return ((Item == that.Item) && (NextHashIndex == that.NextHashIndex)); }
67 bool operator != (const HashItem & that) { return !(*this == that); }
68 };
69
70 // Dynamic Vector of the unique items:
71 DynamicVectorClass<HashItem> Items;
72
73 // Hash table:
74 int HashTableSize;
75 int * HashTable;
76
77 // object which does the hashing for the type
78 HashCalculatorClass<T> * HashCalculator;
79
80 friend class VectorClass;
81 friend class DynamicVectorClass;
82};
83
84
85
86template <class Object,class Key>
88(
89 int initialsize,
90 int growthrate,
92)
93{
94
95}
96
97template <class Object,class Key>
99{
100
101}
102
103template <class Object,class Key>
105{
106 // compute where in the hash table this key would go.
107 HashCalculator->Compute_Hash(key);
108 int hashval = HashCalculator->Get_Hash_Value(0);
109
110 // now try to find an object which has the same key
111 int test_item_index = HashTable[hash];
112 while (test_item_index != 0xFFFFFFFF) {
113 if (HashCalculator->Items_Match(Items[test_item_index].Item,new_item)) {
114 return Items[test_item_index].Object;
115 }
116 test_item_index = Items[test_item_index].NextHashIndex;
117 }
118
119 // couldn't find it
120 return NULL;
121}
122
123#endif
124
125
126#endif
127
Bool operator!=(const AsciiString &s1, const AsciiString &s2)
Bool operator==(const AsciiString &s1, const AsciiString &s2)
#define NULL
Definition BaseType.h:92
WWINLINE Matrix4x4 Add(const Matrix4x4 &a, const Matrix4x4 &b)
Definition matrix4.h:707
~HashTableClass(void)
Definition hash.cpp:61
HashableClass * Find(const char *key)
Definition hash.cpp:117
HashTableClass(int size)
Definition hash.cpp:50