From: Soikk <76824648+Soikk@users.noreply.github.com> Date: Sat, 30 Jul 2022 15:35:47 +0000 (+0200) Subject: added htable delete function X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;h=0e95d2c61da7b7fbce76b0633313128b7440136e;p=soikk-DB.git added htable delete function --- diff --git a/hash-testing/main.c b/hash-testing/main.c index f95b391..23fdbbd 100644 --- a/hash-testing/main.c +++ b/hash-testing/main.c @@ -344,11 +344,13 @@ int main(){ while (fgets(line, sizeof(line), f)) { uint16_t l; char *nline = normalizeStr(line, &l); - uint64_t hash = crc64(0, nline, l); - if(isInArr(arr, hash)){ + uint64_t hash = crc64(SEED, nline, l); + //uint32_t hash = xcrc32(nline, l, SEED); + //uint32_t hash = murmurhash(nline, l, SEED); + /*if(isInArr(arr, hash)){ ++collisions; } - arr[i] = hash; + arr[i] = hash;*/ //printf("%s\t%08x\n", nline, hash); ++i; } diff --git a/hash-testing/main.exe b/hash-testing/main.exe new file mode 100644 index 0000000..3d96212 Binary files /dev/null and b/hash-testing/main.exe differ diff --git a/include/storage.h b/include/storage.h index bef740a..ebf2dc2 100644 --- a/include/storage.h +++ b/include/storage.h @@ -101,6 +101,8 @@ int htableAdd(htable *ht, uint64_t h); uint64_t htableSearch(htable *ht, uint64_t h); +int htableDelete(htable *ht, uint64_t h); + // MTABLE mtable *newMtable(uint64_t size); diff --git a/src/database.c b/src/database.c index ea3a6e0..5595240 100644 --- a/src/database.c +++ b/src/database.c @@ -222,3 +222,9 @@ void debugDatabase(database *db){ } printf("\n"); } + +void reOrderDatabase(database *db){ + + + +} diff --git a/src/storage.c b/src/storage.c index 4ebbfdc..2be4d9e 100644 --- a/src/storage.c +++ b/src/storage.c @@ -142,6 +142,7 @@ int htableAdd(htable *ht, uint64_t h){ return 0; } +// We assume the table isnt ordered as of right now uint64_t htableSearch(htable *ht, uint64_t h){ for(uint64_t i = 0; i < ht->size; ++i){ if(h == ht->table[i]){ @@ -151,6 +152,18 @@ uint64_t htableSearch(htable *ht, uint64_t h){ return -1; } +int htableDelete(htable *ht, uint64_t h){ + uint64_t i = htableSearch(ht, h); + if(i == -1){ + return -1; + } + ht->size--; + for(uint64_t j = i; j < ht->size-1; ++j){ + ht->table[j] = ht->table[j+1]; + } + return 0; +} + mtable *newMtable(uint64_t size){ mtable *mt = malloc(sizeof(mtable)); size = (((uint64_t)size) < 0) ? 0 : size;