Advertisement
Guest User

Untitled

a guest
May 29th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. int containsKey (struct hashMap * ht, KeyType k)
  2. {  
  3.     assert(ht != NULL);
  4.  
  5.     int hashIndex;
  6.  
  7.     if (HASHING_FUNCTION == 1) {
  8.         hashIndex = stringHash1(k) % ht->tableSize;
  9.     }
  10.  
  11.     if (HASHING_FUNCTION == 2) {
  12.         hashIndex = stringHash2(k) % ht->tableSize;
  13.     }
  14.     if (hashIndex < 0) {
  15.         hashIndex += ht->tableSize;
  16.     }
  17.     struct hashLink *searchLink = ht->table[hashIndex];
  18.        
  19.  
  20.     while(searchLink != NULL) {
  21.         if (strcmp(searchLink->key, k) == 0) {
  22.             return 1;
  23.         }
  24.  
  25.         searchLink = searchLink->next;
  26.     }
  27.     return 0;
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement