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->key.val = inode;
|
||||||
bucket->hash = hash;
|
bucket->hash = hash;
|
||||||
bucket->path = path;
|
bucket->path = path;
|
||||||
|
bucket->next = NULL;
|
||||||
return bucket;
|
return bucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) {
|
||||||
} key;
|
} key;
|
||||||
char * target = NULL;
|
char * target = NULL;
|
||||||
size_t idx, hash;
|
size_t idx, hash;
|
||||||
int i;
|
haggis_bucket *b;
|
||||||
|
|
||||||
pthread_mutex_lock(&map->mutex);
|
pthread_mutex_lock(&map->mutex);
|
||||||
if (map->len >= map->capacity)
|
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;
|
key.val = inode;
|
||||||
hash = hash_fnv1a_64(key.bytes, sizeof(ino_t));
|
hash = hash_fnv1a_64(key.bytes, sizeof(ino_t));
|
||||||
idx = map->capacity % hash;
|
idx = map->capacity % hash;
|
||||||
for (i = 0; i < map->capacity; i++) {
|
if (map->buckets[idx].key.val == inode) {
|
||||||
if (map->buckets[idx].key.val == 0) {
|
target = strndup(target, PATH_MAX - 1);
|
||||||
map->buckets[idx].key.val = inode;
|
pthread_mutex_unlock(&map->mutex);
|
||||||
map->buckets[idx].hash = hash;
|
} else if (map->buckets[idx].key.val == 0) {
|
||||||
map->buckets[idx].path = path;
|
map->buckets[idx].key.val = inode;
|
||||||
map->len++;
|
map->buckets[idx].hash = hash;
|
||||||
pthread_mutex_unlock(&map->mutex);
|
map->buckets[idx].path = path;
|
||||||
break;
|
map->len++;
|
||||||
} else if (map->buckets[idx].key.val == inode) {
|
pthread_mutex_unlock(&map->mutex);
|
||||||
target = strndup(target, PATH_MAX - 1);
|
} else {
|
||||||
pthread_mutex_unlock(&map->mutex);
|
b = haggis_bucket_init(key.val, hash, path);
|
||||||
break;
|
if (b == NULL) return NULL;
|
||||||
}
|
haggis_bucket_append(&map->buckets[idx], b);
|
||||||
if (idx == map->capacity - 1)
|
|
||||||
idx = 0;
|
|
||||||
else
|
|
||||||
idx++;
|
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue