X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fhashtable.cpp;fp=libctsupport%2Fhashtable.cpp;h=c7848ef838bf2ff5d6437983674faee77d4a2bd6;hp=c424eb1b521a13d368e2f81d135acdabe64794ef;hb=1a050c98763fbbc0662731b0b76953acede6f5d7;hpb=c8b19dfaffba9f06d8b6c40cb1bb83a8964867f7 diff --git a/libctsupport/hashtable.cpp b/libctsupport/hashtable.cpp index c424eb1..c7848ef 100644 --- a/libctsupport/hashtable.cpp +++ b/libctsupport/hashtable.cpp @@ -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); }