-void
-Hash_PrintStats(tablePtr, proc, clientData)
- Hash_Table *tablePtr; /* Table for which to print info. */
- void (*proc)(); /* Procedure to call to do actual
- * I/O. */
-{
- int count[10], overflow, i, j;
- char msg[100];
- Hash_Entry *hashEntryPtr;
- List_Links *hashList;
-
- for (i=0; i<10; i++) {
- count[i] = 0;
- }
- overflow = 0;
- for (i = 0; i < tablePtr->size; i++) {
- j = 0;
- hashList = &(tablePtr->bucketPtr[i]);
- LIST_FORALL(hashList, (List_Links *) hashEntryPtr) {
- j++;
- }
- if (j < 10) {
- count[j]++;
- } else {
- overflow++;
- }
- }
-
- sprintf(msg, "Entries in table %d number of buckets %d\n",
- tablePtr->numEntries, tablePtr->size);
- (*proc)(clientData, msg);
- for (i = 0; i < 10; i++) {
- sprintf(msg, "Number of buckets with %d entries: %d.\n",
- i, count[i]);
- (*proc)(clientData, msg);
- }
- sprintf(msg, "Number of buckets with > 9 entries: %d.\n",
- overflow);
- (*proc)(clientData, msg);
-}
-\f
-/*
- *---------------------------------------------------------
- *
- * Hash --
- * This is a local procedure to compute a hash table
- * bucket address based on a string value.
- *
- * Results:
- * The return value is an integer between 0 and size - 1.
- *
- * Side Effects:
- * None.
- *
- * Design:
- * It is expected that most keys are decimal numbers,
- * so the algorithm behaves accordingly. The randomizing
- * code is stolen straight from the rand library routine.
- *
- *---------------------------------------------------------
- */
-
-static int
-Hash(tablePtr, key)
- register Hash_Table *tablePtr;
- register char *key;
-{
- register int i = 0;
- register int j;
- register int *intPtr;
-
- switch (tablePtr->keyType) {
- case HASH_STRING_KEYS:
- while (*key != 0) {
- i = (i * 10) + (*key++ - '0');
- }
- break;
- case HASH_ONE_WORD_KEYS:
- i = (int) key;
- break;
- case 2:
- i = ((int *) key)[0] + ((int *) key)[1];
- break;
- default:
- j = tablePtr->keyType;
- intPtr = (int *) key;
- do {
- i += *intPtr++;
- j--;
- } while (j > 0);
- break;
- }
-
-
- return(((i*1103515245 + 12345) >> tablePtr->downShift) & tablePtr->mask);
-}
-\f
-/*
- *---------------------------------------------------------
- *
- * ChainSearch --
- *
- * Search the hash table for the entry in the hash chain.
- *
- * Results:
- * Pointer to entry in hash chain, NULL if none found.
- *
- * Side Effects:
- * None.
- *
- *---------------------------------------------------------
- */
-
-static Hash_Entry *
-ChainSearch(tablePtr, key, hashList)
- Hash_Table *tablePtr; /* Hash table to search. */
- register Address key; /* A hash key. */
- register List_Links *hashList;
-{
- register Hash_Entry *hashEntryPtr;
- register int *hashKeyPtr;
- int *keyPtr;
- register int numKeys;
-
- numKeys = tablePtr->keyType;
- LIST_FORALL(hashList, (List_Links *) hashEntryPtr) {
- switch (numKeys) {
- case 0:
- if (strcmp(hashEntryPtr->key.name, key) == 0) {
- return(hashEntryPtr);
- }
- break;
- case 1:
- if (hashEntryPtr->key.ptr == key) {
- return(hashEntryPtr);
- }
- break;
- case 2:
- hashKeyPtr = hashEntryPtr->key.words;
- keyPtr = (int *) key;
- if (*hashKeyPtr++ == *keyPtr++ && *hashKeyPtr == *keyPtr) {
- return(hashEntryPtr);
- }
- break;
- default:
- if (bcmp((Address) hashEntryPtr->key.words,
- (Address) key, numKeys * sizeof(int))) {
- return(hashEntryPtr);
- }
- break;
- }
- }
-
- /*
- * The desired entry isn't there
- */
-
- return ((Hash_Entry *) NULL);
-}
-\f