start open addressing

This commit is contained in:
Kaehvaman 2024-12-06 22:16:50 +04:00
parent e0f63df0c8
commit b7edf918b1
8 changed files with 5969 additions and 20334 deletions

View File

@ -6,6 +6,7 @@
#include "jhash.h"
#include "fnvhash_32a.h"
#include "crc.h"
// Assumes little endian
void printBits(size_t const size, void const* const ptr) {

View File

@ -1,6 +1,7 @@
#pragma once
#define DICT_TREE_C
#define DICT_HASH_OPEN_ADDRESS_C
#define DICT_HASH_CHAIN_C
/*
Основные операции СЛОВАРЯ:

View File

@ -8,7 +8,7 @@
#include "fnvhash_32a.h"
#include "jhash.h"
#ifdef DICT_HASH_C
#ifdef DICT_HASH_CHAIN_C
struct Node {
char* word;
@ -43,8 +43,9 @@ int hash(char* word) {
struct Node* first[MAX_HASH];
int hash(char* word) {
int hash_value = (int)jhash(word, strlen(word) + 1, FNV1_32A_INIT);
int hash_value = (int)jhash(word, (ub4)strlen(word) + 1, FNV1_32A_INIT);
hash_value = hash_value & hashmask(14);
return hash_value;
}
#elif defined FNV_HASH
@ -56,6 +57,7 @@ struct Node* first[MAX_HASH];
int hash(char* word) {
int hash_value = (int)fnv_32a_str(word, FNV1_32A_INIT);
hash_value = TINY_FNV(14, hash_value);
return hash_value;
}
#endif

View File

@ -0,0 +1,65 @@
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdlib.h>
#include "Dict.h"
#include "fnvhash_32a.h"
#include "jhash.h"
#ifdef DICT_HASH_OPEN_ADDRESS_C
#define MAX_HASH 16384
// Ìàññèâ ñïèñêîâ
char* hashtable[MAX_HASH];
int hash(char* word) {
int hash_value = (int)fnv_32a_str(word, FNV1_32A_INIT);
hash_value = TINY_FNV(14, hash_value);
}
void Insert(char* word) {
int hash_value = hash(word);
while (hashtable[hash_value] != NULL && strcmp(hashtable[hash_value], word) != 0) {
hash_value++;
}
hashtable[hash_value] = (char*)calloc(strlen(word) + 1, sizeof(char));
if (hashtable[hash_value] == NULL) {
puts("Out of memory");
exit(1);
}
strcpy(hashtable[hash_value], word);
}
/* MEMBER ñîîáùàåò, ÿâëÿåòñÿ ëè óêàçàííûé ýëåìåíò ÷ëåíîì äàííîãî ìíîæåñòâà èëè íåò. */
int Member(char* word) {
int hash_value = hash(word);
int i = 0;
while (hashtable[hash_value] != NULL) {
if (strcmp(hashtable[hash_value], word) == 0) {
return 1;
}
}
return 0;
}
/* CREATE - ñîçäàåò ñëîâàðü.
Âûçûâàåòñÿ ïåðåä íà÷àëîì èñïîëüçîâàíèÿ ñëîâàðÿ. */
void Create() {
for (int i = 0; i < MAX_HASH; i++)
hashtable[i] = NULL;
}
/* DESTROY - óíè÷òîæàåò ñëîâàðü.
Âûçûâàåòñÿ ïîñëå îêîí÷àíèÿ èñïîëüçîâàíèÿ ñëîâàðÿ. */
void Destroy() {
for (int i = 0; i < MAX_HASH; i++) {
free(hashtable[i]);
hashtable[i] = NULL;
}
}
#endif

View File

@ -132,7 +132,8 @@
<ClCompile Include="..\..\hash functions\fnvhash_32a.c" />
<ClCompile Include="..\..\hash functions\jhash.c" />
<ClCompile Include="DictArray.c" />
<ClCompile Include="DictHash.c" />
<ClCompile Include="DictHashChain.c" />
<ClCompile Include="DictHashOpenAddress.c" />
<ClCompile Include="DictLinkedList.c" />
<ClCompile Include="DictSortedArray.c" />
<ClCompile Include="DictTree.c" />

View File

@ -15,7 +15,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DictHash.c">
<ClCompile Include="DictHashChain.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="DictLinkedList.c">
@ -39,6 +39,9 @@
<ClCompile Include="..\..\hash functions\jhash.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="DictHashOpenAddress.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Dict.h">

File diff suppressed because one or more lines are too long