Debian Codegraph @

include/hashtable.h

raw
1 /* FILE IDENTIFICATION
2 **
3 ** File Name: hashtable.h
4 ** Author: Kevin Rosenberg
5 ** Purpose: Header file for hash table library
6 ** Date Started: Dec. 2000
7 **
8 ** This is part of the CTSim program
9 ** Copyright (c) 1983-2009 Kevin Rosenberg
10 **
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License (version 2) as
13 ** published by the Free Software Foundation.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** 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 #ifndef HASHTABLE_H
26 #define HASHTABLE_H
27
28
29 class KeywordCodeEntry
30 {
31 private:
32 std::string m_strKeyword;
33 int m_iCode;
34 class KeywordCodeEntry *m_pNext;
35
36 public:
37
38 KeywordCodeEntry (const char* const pszKeyword, int iCode);
39
40 const char* const getKeyword() const
41 { return m_strKeyword.c_str(); }
42
43 bool matchesKeyword (const char* const pszMatch) const;
44
45 int getCode () const
46 { return m_iCode; }
47
48 void setCode (int iCode)
49 { m_iCode = iCode; }
50
51 void setNext (KeywordCodeEntry* pNext)
52 { m_pNext = pNext; }
53
54 KeywordCodeEntry* getNext ()
55 { return m_pNext; }
56 };
57
58
59 class KeywordCodeHashTable {
60 public:
61 enum {
62 HASHSIZE = 100,
63 };
64
65 KeywordCodeHashTable()
66 { initTable(); }
67
68 ~KeywordCodeHashTable()
69 { freeTable(); }
70
71 void installKeywordCode (const char* const pszKeyword, int iCode);
72 KeywordCodeEntry* lookup (const char* const pszKeyword);
73
74 private:
75 KeywordCodeEntry* m_hashTable[HASHSIZE];
76
77 int hash (const char* s);
78 void initTable ();
79 void freeTable ();
80 };
81
82 #endif
83
84