Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
hash.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/* $Header: /Commando/Code/wwlib/hash.h 2 6/15/00 10:53a Byon_g $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D Library *
25 * *
26 * $Archive:: /Commando/Code/wwlib/hash.h $*
27 * *
28 * Author:: Greg_h *
29 * *
30 * $Modtime:: 6/15/00 9:43a $*
31 * *
32 * $Revision:: 2 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef HASH_H
44#define HASH_H
45
46#include "always.h"
47
49
50
51/*
52** HashableClass
53*/
55
56public:
57 HashableClass( void ) : NextHash( NULL ) {}
58 virtual ~HashableClass( void ) {}
59
60 virtual const char * Get_Key( void ) = 0;
61
62private:
63 HashableClass * NextHash;
64 friend class HashTableClass;
66};
67
68
69/*
70** HashTableClass
71*/
73
74public:
75 HashTableClass( int size );
76 ~HashTableClass( void );
77
78 void Reset( void );
79 void Add( HashableClass * entry );
80 bool Remove( HashableClass * entry );
81
82 HashableClass * Find( const char * key );
83
84private:
85 // HashTableSize MUST be a power of two
86 int HashTableSize;
87 HashableClass * * HashTable;
88
89 // Convert key to a table index
90 int Hash( const char * key );
91
93};
94
95
96/*
97**
98*/
100{
101public:
102 HashTableIteratorClass( HashTableClass & table ) : Table( table ) {}
103 virtual ~HashTableIteratorClass( void ) {}
104
105 void First( void );
106 void Next( void );
107 bool Is_Done( void ) { return CurrentEntry == NULL; }
108 HashableClass * Get_Current( void ) { return CurrentEntry; }
109
110private:
111 const HashTableClass & Table;
112 int Index;
113 HashableClass * CurrentEntry;
114 HashableClass * NextEntry;
115
116 void Advance_Next( void );
117};
118
119
120#endif // HASH_H
#define NULL
Definition BaseType.h:92
void Add(HashableClass *entry)
Definition hash.cpp:77
~HashTableClass(void)
Definition hash.cpp:61
bool Remove(HashableClass *entry)
Definition hash.cpp:87
friend class HashTableIteratorClass
Definition hash.h:92
HashableClass * Find(const char *key)
Definition hash.cpp:117
void Reset(void)
Definition hash.cpp:70
HashTableClass(int size)
Definition hash.cpp:50
HashableClass * Get_Current(void)
Definition hash.h:108
HashTableIteratorClass(HashTableClass &table)
Definition hash.h:102
virtual ~HashTableIteratorClass(void)
Definition hash.h:103
bool Is_Done(void)
Definition hash.h:107
friend class HashTableClass
Definition hash.h:64
virtual const char * Get_Key(void)=0
virtual ~HashableClass(void)
Definition hash.h:58
friend class HashTableIteratorClass
Definition hash.h:65
HashableClass(void)
Definition hash.h:57