-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHashTable.c
More file actions
33 lines (31 loc) · 1.11 KB
/
Copy pathHashTable.c
File metadata and controls
33 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdlib.h>
#include "HashTable.h"
// Returns 1 if the item already exists in the hash table, and returns 0 if a new item was added
int insertHashItem(hashTable* table, intptr_t value, int update)
{
int mod = table->len;
int i = 80933 * (unsigned int)(value ^ (value >> 5)) % mod;
while (table->items[i % mod].value && (table->items[i % mod].updateCount == update) && i < (2 * mod))
{
if (table->items[i % mod].value == value) { return 1; }
i++;
} // increment untill there is a free space
table->items[i % mod].value = value;
table->items[i % mod].updateCount = update;
table->num++;
return 0;
}
/*
int findHashItem(hashTable* table, intptr_t lookup, int update)
{
int mod = table->len;
int i = 80933 * (unsigned int)lookup % mod;
// increment untill there is a free space or the item is found
while (table->items[i % mod].value && (table->items[i % mod].updateCount == update) && i < (2 * mod))
{
if ((table->items[i % mod].value == lookup) && (table->items[i % mod].updateCount == update)) { return 1; }
i++;
}
return 0;
}
*/