X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fhashtable.cpp;h=c7848ef838bf2ff5d6437983674faee77d4a2bd6;hp=df2a047adb1874669cc1a7025182e67eafbd04de;hb=f7ee98f7d964ed361068179f0e7ea4475ed1abdf;hpb=9f29c8b32c972db1178d6f8551d5cd57ceb67083 diff --git a/libctsupport/hashtable.cpp b/libctsupport/hashtable.cpp index df2a047..c7848ef 100644 --- a/libctsupport/hashtable.cpp +++ b/libctsupport/hashtable.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: hashtable.cpp,v 1.3 2001/01/28 19:10:18 kevin Exp $ +** $Id$ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -35,7 +35,7 @@ KeywordCodeEntry::KeywordCodeEntry (const char* const pszKeyword, int iCode) { 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; @@ -50,7 +50,7 @@ KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const { 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; @@ -67,48 +67,48 @@ KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const // 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); } @@ -118,10 +118,10 @@ KeywordCodeHashTable::lookup (const char* const pszLookup) { 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); } @@ -131,11 +131,11 @@ KeywordCodeHashTable::installKeywordCode (const char* const pszKeyword, int iCod { 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); }