This commit is contained in:
Timerix22 2022-02-10 17:32:18 +03:00
parent b00b2b69f3
commit f39efbb20d
8 changed files with 114 additions and 43 deletions

View File

@ -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;i<height;i++)
h.rows[i]=Autoarr_create(100,8,type);
return h;
}
void Hashtable_clear(Hashtable* ht){
for(uint16 i=0;i<ht->height;i++)
Autoarr_clear((Autoarr*)(ht->rows+i));
free(ht->rows);
ht->type=Null;
}
void Hashtable_add_uni(Hashtable* ht,hash_t hash, Unitype val){
}

View File

@ -1 +1,17 @@
#include "../base/base.h"
#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);

View File

@ -0,0 +1,3 @@
#include "hash.h"

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -11,5 +11,7 @@
#include <unistd.h>
#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)
#define dbg(N) printf("\e[95m%d\n",N)

View File

@ -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;
}