r328: *** empty log message ***
[ctsim.git] / include / hashtable.h
1 /* FILE IDENTIFICATION\r
2 **\r
3 **      File Name:      hashtable.h\r
4 **      Author:         Kevin Rosenberg\r
5 **      Purpose:        Header file for hash table library\r
6 **      Date Started:   Dec. 2000\r
7 **\r
8 **  This is part of the CTSim program\r
9 **  Copyright (C) 1983-2000 Kevin Rosenberg\r
10 **\r
11 **  $Id: hashtable.h,v 1.1 2000/12/27 20:09:19 kevin Exp $\r
12 **\r
13 **\r
14 **  This program is free software; you can redistribute it and/or modify\r
15 **  it under the terms of the GNU General Public License (version 2) as\r
16 **  published by the Free Software Foundation.\r
17 **\r
18 **  This program is distributed in the hope that it will be useful,\r
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
21 **  GNU General Public License for more details.\r
22 **\r
23 **  You should have received a copy of the GNU General Public License\r
24 **  along with this program; if not, write to the Free Software\r
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
26 ******************************************************************************/\r
27 \r
28 #ifndef HASHTABLE_H\r
29 #define HASHTABLE_H\r
30 \r
31 \r
32 class KeywordCodeEntry\r
33 {\r
34 private:\r
35   std::string m_strKeyword;\r
36   int m_iCode;\r
37   class KeywordCodeEntry *m_pNext;\r
38   \r
39   public:\r
40     \r
41     KeywordCodeEntry (const char* const pszKeyword, int iCode);\r
42     \r
43     const char* const getKeyword() const\r
44     { return m_strKeyword.c_str(); }\r
45 \r
46     bool matchesKeyword (const char* const pszMatch) const;\r
47 \r
48     int getCode () const\r
49     { return m_iCode; }\r
50     \r
51     void setCode (int iCode) \r
52     { m_iCode = iCode; }\r
53     \r
54     void setNext (KeywordCodeEntry* pNext)\r
55     { m_pNext = pNext; }\r
56     \r
57     KeywordCodeEntry* getNext ()\r
58     { return m_pNext; }\r
59 };\r
60 \r
61 \r
62 class KeywordCodeHashTable {\r
63 public:\r
64   enum {\r
65     HASHSIZE = 100,\r
66   };\r
67   \r
68   KeywordCodeHashTable()\r
69   { initTable(); }\r
70   \r
71   ~KeywordCodeHashTable()\r
72   { freeTable(); }\r
73   \r
74   void installKeywordCode (const char* const pszKeyword, int iCode);\r
75   KeywordCodeEntry* lookup (const char* const pszKeyword);\r
76   \r
77 private:\r
78   KeywordCodeEntry* m_hashTable[HASHSIZE];\r
79   \r
80   int hash (const char* s);\r
81   void initTable ();\r
82   void freeTable ();\r
83 };\r
84 \r
85 #endif\r
86 \r
87 \r