{
int nLength = strlen (pszKeyword);
char* pszCopy = new char [ nLength + 1];
- for (int i = 0; i < nLength; i++)
+ for (int i = 0; i < nLength; i++)
pszCopy[i] = tolower (pszKeyword[i]);
pszCopy[nLength] = 0;
{
int nLength = strlen (pszCompare);
char* pszCopy = new char [ nLength + 1];
- for (int i = 0; i < nLength; i++)
+ for (int i = 0; i < nLength; i++)
pszCopy[i] = tolower (pszCompare[i]);
pszCopy[nLength] = 0;
// inittable (table)
// clear symbol table
-void
+void
KeywordCodeHashTable::initTable ()
{
- int i;
+ int i;
- for (i = 0; i < HASHSIZE; i++)
- m_hashTable[i] = NULL;
+ for (i = 0; i < HASHSIZE; i++)
+ m_hashTable[i] = NULL;
}
// freetable (table)
-// free all memory allocated to table, then clear table
+// free all memory allocated to table, then clear table
-void
+void
KeywordCodeHashTable::freeTable ()
{
- int i;
- KeywordCodeEntry *p, *np;
-
- for (i = 0; i < HASHSIZE; i++) {
- np = m_hashTable [i];
- while (np != NULL) {
- p = np->getNext();
- delete np;
- np = p;
+ int i;
+ KeywordCodeEntry *p, *np;
+
+ for (i = 0; i < HASHSIZE; i++) {
+ np = m_hashTable [i];
+ while (np != NULL) {
+ p = np->getNext();
+ delete np;
+ np = p;
}
- }
- initTable ();
+ }
+ initTable ();
}
-// form hash value of string s
-int
+// form hash value of string s
+int
KeywordCodeHashTable::hash (const char* s)
{
- int hashval = 0;
+ int hashval = 0;
while (*s != EOS) {
- hashval += tolower(*s);
+ hashval += tolower(*s);
s++;
}
- return (hashval % HASHSIZE);
+ return (hashval % HASHSIZE);
}
{
KeywordCodeEntry *found = NULL;
for (KeywordCodeEntry* np = m_hashTable[ hash( pszLookup ) ]; np != NULL; np = np->getNext())
- if (np->matchesKeyword (pszLookup)) {
- found = np; // found it
- break;
- }
+ if (np->matchesKeyword (pszLookup)) {
+ found = np; // found it
+ break;
+ }
return (found);
}
{
KeywordCodeEntry *np = lookup (pszKeyword);
- if (np == NULL) { // not found
- np = new KeywordCodeEntry (pszKeyword, iCode);
- int hashval = hash (np->getKeyword());
- np->setNext (m_hashTable[ hashval ]);
- m_hashTable[hashval] = np;
- } else // already defined
- np->setCode (iCode);
+ if (np == NULL) { // not found
+ np = new KeywordCodeEntry (pszKeyword, iCode);
+ int hashval = hash (np->getKeyword());
+ np->setNext (m_hashTable[ hashval ]);
+ m_hashTable[hashval] = np;
+ } else // already defined
+ np->setCode (iCode);
}