Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){
* to store the point to the item, or MAP_FULL.
*/
int hashmap_hash(map_t in, char* key){
int curr;
int curr, tmp;
int i;

/* Cast the hashmap */
Expand All @@ -200,14 +200,20 @@ int hashmap_hash(map_t in, char* key){

/* Find the best index */
curr = hashmap_hash_int(m, key);
tmp = curr;

/* Linear probing */
for(i = 0; i< MAX_CHAIN_LENGTH; i++){
if(m->data[curr].in_use == 0)
return curr;
if(m->data[tmp].in_use == 1 && (strcmp(m->data[tmp].key,key)==0))
return tmp;

if(m->data[curr].in_use == 1 && (strcmp(m->data[curr].key,key)==0))
tmp = (tmp + 1) % m->table_size;
}
for (i = 0; i < MAX_CHAIN_LENGTH; i++) {
if (m->data[curr].in_use == 0) {
m->size++;
return curr;
}

curr = (curr + 1) % m->table_size;
}
Expand Down Expand Up @@ -278,7 +284,6 @@ int hashmap_put(map_t in, char* key, any_t value){
m->data[index].data = value;
m->data[index].key = key;
m->data[index].in_use = 1;
m->size++;

return MAP_OK;
}
Expand Down