From daeb29299f8186b6c432b482deedd51fc3083912 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Mon, 14 Feb 2022 21:23:11 +0300 Subject: [PATCH] 74 --- DtsodC/src/Hashtable/Hashtable.c | 20 +++++++++++--------- DtsodC/src/Hashtable/Hashtable.h | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/DtsodC/src/Hashtable/Hashtable.c b/DtsodC/src/Hashtable/Hashtable.c index 3b45aba..3da9dca 100644 --- a/DtsodC/src/Hashtable/Hashtable.c +++ b/DtsodC/src/Hashtable/Hashtable.c @@ -1,24 +1,26 @@ #include "Hashtable.h" -Hashtable Hashtable_create(uint16 height,my_type type){ +Hashtable Hashtable_create(uint16 height){ Hashtable h={ - .type=type, .height=height, - .rows=malloc(height*sizeof(Autoarr)) + .rows=malloc(height*sizeof(Autoarr*)) }; - for(uint16 i=0;iheight;i++) - Autoarr_clear((Autoarr*)(ht->rows+i)); + Autoarr_clear(ht->rows[i]); free(ht->rows); - ht->type=Null; } -void Hashtable_add_uni(Hashtable* ht,uint32 hash, Unitype val){ - +void Hashtable_add_kvpair(Hashtable* ht, KeyValuePair pair){ + uint16 i=ht->height%ihash(pair.key); + if(!ht->rows[i]) + ht->rows[i]=Autoarr_create(100,4,ht->type); + Autoarr_add_kvpair(ht->rows[i],pair); } +void Hashtable_add(Hashtable* ht, char* key, Unitype value){ + Hashtable_add_kvpair(ht,(KeyValuePair){key,value}); +} diff --git a/DtsodC/src/Hashtable/Hashtable.h b/DtsodC/src/Hashtable/Hashtable.h index a249c9d..823c936 100644 --- a/DtsodC/src/Hashtable/Hashtable.h +++ b/DtsodC/src/Hashtable/Hashtable.h @@ -5,11 +5,21 @@ #include "hash.h" typedef struct Hashtable{ - my_type type; // data type - uint16 height; // amount of rows - Autoarr* rows; // Autoarr[height]s + uint16 height; // amount of rows + Autoarr** rows; // Autoarr[height]s } Hashtable; Hashtable Hashtable_create(uint16 height,my_type type); void Hashtable_clear(Hashtable* ht); + +typedef struct KeyValuePair{ + char* key; + Unitype value; +} KeyValuePair; + +const uint16 Hashtable_HTINY=61; +const uint16 Hashtable_HSMALL=631; +const uint16 Hashtable_HMED=3889; +const uint16 Hashtable_HLARGE=19441; +const uint16 Hashtable_HMAX=65536;