diff --git a/DtsodC/src/Hashtable/Hashtable.c b/DtsodC/src/Hashtable/Hashtable.c index e69de29..131b45d 100644 --- a/DtsodC/src/Hashtable/Hashtable.c +++ b/DtsodC/src/Hashtable/Hashtable.c @@ -0,0 +1,24 @@ +#include "Hashtable.h" + +Hashtable Hashtable_create(uint16 height,my_type type){ + Hashtable h={ + .type=type, + .height=height, + .rows=malloc(height*sizeof(Autoarr)) + }; + for(uint16 i=0;iheight;i++) + Autoarr_clear((Autoarr*)(ht->rows+i)); + free(ht->rows); + ht->type=Null; +} + +void Hashtable_add_uni(Hashtable* ht,hash_t hash, Unitype val){ + +} + diff --git a/DtsodC/src/Hashtable/Hashtable.h b/DtsodC/src/Hashtable/Hashtable.h index d75cd09..d05e3d3 100644 --- a/DtsodC/src/Hashtable/Hashtable.h +++ b/DtsodC/src/Hashtable/Hashtable.h @@ -1 +1,17 @@ -#include "../base/base.h" \ No newline at end of file +#pragma once + +#include "../base/base.h" +#include "../Autoarr/Autoarr.h" +#include "hash.h" + +typedef struct Hashtable{ + my_type type; // data type + uint16 height; // amount of rows + Autoarr* rows; // Autoarr[height]s +} Hashtable; + +Hashtable Hashtable_create(uint16 height,my_type type); + +void Hashtable_clear(Hashtable* ht); + +void Hashtable_add_uni(Hashtable* ht,hash_t hash, Unitype val); diff --git a/DtsodC/src/Hashtable/hash.c b/DtsodC/src/Hashtable/hash.c new file mode 100644 index 0000000..a533fd4 --- /dev/null +++ b/DtsodC/src/Hashtable/hash.c @@ -0,0 +1,3 @@ +#include "hash.h" + + diff --git a/DtsodC/src/Hashtable/hash.h b/DtsodC/src/Hashtable/hash.h new file mode 100644 index 0000000..d36b4b5 --- /dev/null +++ b/DtsodC/src/Hashtable/hash.h @@ -0,0 +1,8 @@ +#pragma once + +#include "../base/base.h" + +typedef uint32 hash_t; + +//djb2 hash function from http://www.cse.yorku.ca/~oz/hash.html +hash_t dhash(char *str); diff --git a/DtsodC/src/base/base.h b/DtsodC/src/base/base.h index bc63125..2d123d0 100644 --- a/DtsodC/src/base/base.h +++ b/DtsodC/src/base/base.h @@ -7,6 +7,3 @@ // just sleeping function // dont set 'milisec' > 1000 for good perfomance void msleep(uint8 sec, uint16 milisec); - -//djb2 hash function from http://www.cse.yorku.ca/~oz/hash.html -uint32 hash(char *str); \ No newline at end of file diff --git a/DtsodC/src/base/hash.c b/DtsodC/src/base/hash.c deleted file mode 100644 index da5ca47..0000000 --- a/DtsodC/src/base/hash.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "base.h" - -uint32 hash(char *str){ - uint32 hash=5381; - char c; - while (c=*str++) - hash=((hash << 5) + hash) + c; //hash=hash*33^c - return hash; -} \ No newline at end of file diff --git a/DtsodC/src/base/std.h b/DtsodC/src/base/std.h index f644107..e3d7ce0 100644 --- a/DtsodC/src/base/std.h +++ b/DtsodC/src/base/std.h @@ -11,5 +11,7 @@ #include #define CHOOSE(B, Y, N) __builtin_choose_expr(B, Y, N) + #define IFTYPE(X, T) __builtin_types_compatible_p(typeof(X), T) -#define dbg(N) printf("\e[95m%d\n",N) \ No newline at end of file + +#define dbg(N) printf("\e[95m%d\n",N) diff --git a/DtsodC/src/main.c b/DtsodC/src/main.c index 92ab075..cd11c62 100644 --- a/DtsodC/src/main.c +++ b/DtsodC/src/main.c @@ -1,29 +1,59 @@ -#include "base/base.h" -#include "tests/tests.h" -#include "Autoarr/Autoarr.h" -#include "SearchTree/SearchTree.h" - -#define clrscr() printf("\e[1;1H\e[2J") - -int main(){ - setlocale(LC_ALL, "en-US.Unicode"); - printf("\e[92mdtsod parser in c language!\e[97m\n"); - test_all(); - Unitype a={Double,.Double=9}; - STNode* node=STNode_create(); - ST_push(node,"type", a); - ST_push(node,"time", a); - ST_push(node,"author_id", a); - ST_push(node,"channel_id", a); - ST_push(node,"message_id", a); - ST_push(node,"text", a); - ST_push(node,"files", a); - a=ST_pull(node,""); - //STNode_free(node); - printf("%u\n", hash("000")); - printf("%u\n", hash("0000")); - printf("%u\n", hash("1111")); - - - return 0; -} +#include "base/base.h" + +#include "tests/tests.h" + +#include "Autoarr/Autoarr.h" + +#include "SearchTree/SearchTree.h" +#include "Hashtable/hash.c" + + + +#define clrscr() printf("\e[1;1H\e[2J") + + + +int main(){ + + setlocale(LC_ALL, "en-US.Unicode"); + + printf("\e[92mdtsod parser in c language!\e[97m\n"); + + test_all(); + + Unitype a={Double,.Double=9}; + + STNode* node=STNode_create(); + + ST_push(node,"type", a); + + ST_push(node,"time", a); + + ST_push(node,"author_id", a); + + ST_push(node,"channel_id", a); + + ST_push(node,"message_id", a); + + ST_push(node,"text", a); + + ST_push(node,"files", a); + + a=ST_pull(node,""); + + //STNode_free(node); + + printf("%u\n", dhash("000")); + + printf("%u\n", dhash("0000")); + + printf("%u\n", dhash("1111")); + + + + + + return 0; + +} +