Changeset 889 for trunk/psLib/src/sysUtils
- Timestamp:
- Jun 6, 2004, 2:32:53 PM (22 years ago)
- Location:
- trunk/psLib/src/sysUtils
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psHash.c
r885 r889 1 /****************************************************************************** 2 An interface to hash tables for Pan-STARRS 3 4 Collisions are handled by simple linked lists 5 *****************************************************************************/ 1 /** @file psHash.c 2 * 3 * @brief Contains support for basic hashing functions. 4 * 5 * This file will hold the functions for defining a hash table with arbitrary 6 * data types, allocating/deallocating that has table, adding and removing 7 * data from that hash table, and listing all keys defined in the hash table. 8 * 9 * @author Robert Lupton, Princeton University 10 * @author George Gusciora, MHPCC 11 * 12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-06-07 00:32:53 $ 14 * 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 */ 6 17 #include <stdlib.h> 7 18 #include <stdio.h> … … 12 23 #include "psString.h" 13 24 #include "psTrace.h" 25 #include "psAbort.h" 14 26 15 27 psDlist *psHashKeyList(psHash *table) … … 142 154 // bucket. 143 155 psHashBucket *optr = NULL; 156 char *tmpchar = NULL; 144 157 145 158 // NOTE: this is NOT a good hash function! See Knuth. 146 159 // 147 for (int i = 0, len = strlen(key); i < len; i++) { 148 hash = (hash << 1) ^ key[i]; 149 } 150 hash &= (table->nbucket - 1); 160 // for (int i = 0, len = strlen(key); i < len; i++) { 161 // hash = (hash << 1) ^ key[i]; 162 // } 163 // hash &= (table->nbucket - 1); 164 165 // This hash algorithm is from Sedgewick. NOTE: must reread to ensure that 166 // the size of the hash table is not required to be a prime number. 167 tmpchar = (char *) key; 168 for (hash = 0; *tmpchar != '\0'; tmpchar++) { 169 hash = (64 * hash + *tmpchar) % (table->nbucket); 170 } 171 172 // NOTE: This should not be necessary, but for now, I'm checking bounds 173 // anyway. 174 if ((hash < 0) || 175 (hash >= table->nbucket)) { 176 psAbort(__func__,"Internal hash function out of range (%d)", 177 hash); 178 } 151 179 152 180 ptr = table->buckets[hash]; -
trunk/psLib/src/sysUtils/psHash.h
r886 r889 1 /** @file psHash.c 2 * 3 * @brief Contains support for basic hashing functions. 4 * 5 * This file will hold the prototypes for defining a hash table with arbitrary 6 * data types, allocating/deallocating that has table, adding and removing 7 * data from that hash table, and listing all keys defined in the hash table. 8 * 9 * @author Robert Lupton, Princeton University 10 * @author George Gusciora, MHPCC 11 * 12 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-06-07 00:32:53 $ 14 * 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 */ 17 1 18 #if !defined(PS_HASH_H) 2 19 #define PS_HASH_H -
trunk/psLib/src/sysUtils/psLogMsg.c
r560 r889 29 29 static int logDest = PS_LOG_TO_STDERR; // where to log messages 30 30 static int logLevel = PS_LOG_INFO; // log all messages at this or above 31 //static FILE *p_logFP = NULL; 31 32 // The following variables control 32 33 // which information is displayed in
Note:
See TracChangeset
for help on using the changeset viewer.
