71
This commit is contained in:
parent
b00b2b69f3
commit
f39efbb20d
@ -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){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -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);
|
||||||
|
|||||||
3
DtsodC/src/Hashtable/hash.c
Normal file
3
DtsodC/src/Hashtable/hash.c
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "hash.h"
|
||||||
|
|
||||||
|
|
||||||
8
DtsodC/src/Hashtable/hash.h
Normal file
8
DtsodC/src/Hashtable/hash.h
Normal 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);
|
||||||
@ -7,6 +7,3 @@
|
|||||||
// just sleeping function
|
// just sleeping function
|
||||||
// dont set 'milisec' > 1000 for good perfomance
|
// dont set 'milisec' > 1000 for good perfomance
|
||||||
void msleep(uint8 sec, uint16 milisec);
|
void msleep(uint8 sec, uint16 milisec);
|
||||||
|
|
||||||
//djb2 hash function from http://www.cse.yorku.ca/~oz/hash.html
|
|
||||||
uint32 hash(char *str);
|
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
@ -11,5 +11,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define CHOOSE(B, Y, N) __builtin_choose_expr(B, Y, N)
|
#define CHOOSE(B, Y, N) __builtin_choose_expr(B, Y, N)
|
||||||
|
|
||||||
#define IFTYPE(X, T) __builtin_types_compatible_p(typeof(X), T)
|
#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)
|
||||||
|
|||||||
@ -1,29 +1,59 @@
|
|||||||
#include "base/base.h"
|
#include "base/base.h"
|
||||||
#include "tests/tests.h"
|
|
||||||
#include "Autoarr/Autoarr.h"
|
#include "tests/tests.h"
|
||||||
#include "SearchTree/SearchTree.h"
|
|
||||||
|
#include "Autoarr/Autoarr.h"
|
||||||
#define clrscr() printf("\e[1;1H\e[2J")
|
|
||||||
|
#include "SearchTree/SearchTree.h"
|
||||||
int main(){
|
#include "Hashtable/hash.c"
|
||||||
setlocale(LC_ALL, "en-US.Unicode");
|
|
||||||
printf("\e[92mdtsod parser in c language!\e[97m\n");
|
|
||||||
test_all();
|
|
||||||
Unitype a={Double,.Double=9};
|
#define clrscr() printf("\e[1;1H\e[2J")
|
||||||
STNode* node=STNode_create();
|
|
||||||
ST_push(node,"type", a);
|
|
||||||
ST_push(node,"time", a);
|
|
||||||
ST_push(node,"author_id", a);
|
int main(){
|
||||||
ST_push(node,"channel_id", a);
|
|
||||||
ST_push(node,"message_id", a);
|
setlocale(LC_ALL, "en-US.Unicode");
|
||||||
ST_push(node,"text", a);
|
|
||||||
ST_push(node,"files", a);
|
printf("\e[92mdtsod parser in c language!\e[97m\n");
|
||||||
a=ST_pull(node,"");
|
|
||||||
//STNode_free(node);
|
test_all();
|
||||||
printf("%u\n", hash("000"));
|
|
||||||
printf("%u\n", hash("0000"));
|
Unitype a={Double,.Double=9};
|
||||||
printf("%u\n", hash("1111"));
|
|
||||||
|
STNode* node=STNode_create();
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user