r316: c++ conversions to POL
[ctsim.git] / include / hashtable.h
diff --git a/include/hashtable.h b/include/hashtable.h
new file mode 100644 (file)
index 0000000..0f97edf
--- /dev/null
@@ -0,0 +1,87 @@
+/* FILE IDENTIFICATION\r
+**\r
+**     File Name:      hashtable.h\r
+**     Author:         Kevin Rosenberg\r
+**     Purpose:        Header file for hash table library\r
+**     Date Started:   Dec. 2000\r
+**\r
+**  This is part of the CTSim program\r
+**  Copyright (C) 1983-2000 Kevin Rosenberg\r
+**\r
+**  $Id: hashtable.h,v 1.1 2000/12/27 20:09:19 kevin Exp $\r
+**\r
+**\r
+**  This program is free software; you can redistribute it and/or modify\r
+**  it under the terms of the GNU General Public License (version 2) as\r
+**  published by the Free Software Foundation.\r
+**\r
+**  This program is distributed in the hope that it will be useful,\r
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+**  GNU General Public License for more details.\r
+**\r
+**  You should have received a copy of the GNU General Public License\r
+**  along with this program; if not, write to the Free Software\r
+**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+******************************************************************************/\r
+\r
+#ifndef HASHTABLE_H\r
+#define HASHTABLE_H\r
+\r
+\r
+class KeywordCodeEntry\r
+{\r
+private:\r
+  std::string m_strKeyword;\r
+  int m_iCode;\r
+  class KeywordCodeEntry *m_pNext;\r
+  \r
+  public:\r
+    \r
+    KeywordCodeEntry (const char* const pszKeyword, int iCode);\r
+    \r
+    const char* const getKeyword() const\r
+    { return m_strKeyword.c_str(); }\r
+\r
+    bool matchesKeyword (const char* const pszMatch) const;\r
+\r
+    int getCode () const\r
+    { return m_iCode; }\r
+    \r
+    void setCode (int iCode) \r
+    { m_iCode = iCode; }\r
+    \r
+    void setNext (KeywordCodeEntry* pNext)\r
+    { m_pNext = pNext; }\r
+    \r
+    KeywordCodeEntry* getNext ()\r
+    { return m_pNext; }\r
+};\r
+\r
+\r
+class KeywordCodeHashTable {\r
+public:\r
+  enum {\r
+    HASHSIZE = 100,\r
+  };\r
+  \r
+  KeywordCodeHashTable()\r
+  { initTable(); }\r
+  \r
+  ~KeywordCodeHashTable()\r
+  { freeTable(); }\r
+  \r
+  void installKeywordCode (const char* const pszKeyword, int iCode);\r
+  KeywordCodeEntry* lookup (const char* const pszKeyword);\r
+  \r
+private:\r
+  KeywordCodeEntry* m_hashTable[HASHSIZE];\r
+  \r
+  int hash (const char* s);\r
+  void initTable ();\r
+  void freeTable ();\r
+};\r
+\r
+#endif\r
+\r
+\r