Insert new buckets into linked list for for linkmap
This commit is contained in:
parent
6a58dd2a63
commit
e266346bf2
1 changed files with 15 additions and 18 deletions
33
linkmap.c
33
linkmap.c
|
@ -48,6 +48,7 @@ haggis_bucket* haggis_bucket_init(ino_t inode, uint64_t hash, char * path) {
|
|||
bucket->key.val = inode;
|
||||
bucket->hash = hash;
|
||||
bucket->path = path;
|
||||
bucket->next = NULL;
|
||||
return bucket;
|
||||
}
|
||||
|
||||
|
@ -110,7 +111,7 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) {
|
|||
} key;
|
||||
char * target = NULL;
|
||||
size_t idx, hash;
|
||||
int i;
|
||||
haggis_bucket *b;
|
||||
|
||||
pthread_mutex_lock(&map->mutex);
|
||||
if (map->len >= map->capacity)
|
||||
|
@ -118,23 +119,19 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) {
|
|||
key.val = inode;
|
||||
hash = hash_fnv1a_64(key.bytes, sizeof(ino_t));
|
||||
idx = map->capacity % hash;
|
||||
for (i = 0; i < map->capacity; i++) {
|
||||
if (map->buckets[idx].key.val == 0) {
|
||||
map->buckets[idx].key.val = inode;
|
||||
map->buckets[idx].hash = hash;
|
||||
map->buckets[idx].path = path;
|
||||
map->len++;
|
||||
pthread_mutex_unlock(&map->mutex);
|
||||
break;
|
||||
} else if (map->buckets[idx].key.val == inode) {
|
||||
target = strndup(target, PATH_MAX - 1);
|
||||
pthread_mutex_unlock(&map->mutex);
|
||||
break;
|
||||
}
|
||||
if (idx == map->capacity - 1)
|
||||
idx = 0;
|
||||
else
|
||||
idx++;
|
||||
if (map->buckets[idx].key.val == inode) {
|
||||
target = strndup(target, PATH_MAX - 1);
|
||||
pthread_mutex_unlock(&map->mutex);
|
||||
} else if (map->buckets[idx].key.val == 0) {
|
||||
map->buckets[idx].key.val = inode;
|
||||
map->buckets[idx].hash = hash;
|
||||
map->buckets[idx].path = path;
|
||||
map->len++;
|
||||
pthread_mutex_unlock(&map->mutex);
|
||||
} else {
|
||||
b = haggis_bucket_init(key.val, hash, path);
|
||||
if (b == NULL) return NULL;
|
||||
haggis_bucket_append(&map->buckets[idx], b);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue