75
This commit is contained in:
parent
daeb29299f
commit
a25f5bd5f1
4
DtsodC/.vscode/settings.json
vendored
4
DtsodC/.vscode/settings.json
vendored
@ -4,7 +4,9 @@
|
||||
"cstdint": "c",
|
||||
"limits": "c",
|
||||
"cstdio": "c",
|
||||
"cwchar": "c"
|
||||
"cwchar": "c",
|
||||
"compare": "c",
|
||||
"type_traits": "c"
|
||||
},
|
||||
"C_Cpp.default.defines": [],
|
||||
"C_Cpp.intelliSenseCacheSize": 10
|
||||
|
||||
67
DtsodC/src/Autoarr/new.h
Normal file
67
DtsodC/src/Autoarr/new.h
Normal file
@ -0,0 +1,67 @@
|
||||
#define Autoarr_length(autoarr) (uint32)(autoarr->max_block_length*(autoarr->max_blocks_count-1)+autoarr->block_length)
|
||||
#define Autoarr_max_length(autoarr) (uint32)(autoarr->max_block_length*autoarr->max_blocks_count)
|
||||
|
||||
#define define_Autoarr(type) \
|
||||
typedef struct Autoarr_##type{ \
|
||||
uint16 blocks_count; \
|
||||
uint16 max_blocks_count; \
|
||||
uint16 block_length; \
|
||||
uint16 max_block_length; \
|
||||
type** values; \
|
||||
void (*Autoarr_add)(struct Autoarr_##type* ar, type element); \
|
||||
type (*Autoarr_get)(struct Autoarr_##type* ar, uint32 index); \
|
||||
void (*Autoarr_set)(struct Autoarr_##type* ar, uint32 index, type element); \
|
||||
} Autoarr_##type; \
|
||||
\
|
||||
void Autoarr_add_##type(struct Autoarr_##type* ar, type element){ \
|
||||
if(!ar->values){ \
|
||||
ar->values=malloc(ar->max_blocks_count*sizeof(type*)); \
|
||||
ar->values[0]=malloc(ar->max_block_length*sizeof(type)); \
|
||||
goto create_block; \
|
||||
} \
|
||||
if(ar->block_length==ar->max_block_length){ \
|
||||
if (ar->blocks_count>=ar->max_blocks_count) throw(ERR_MAXLENGTH); \
|
||||
ar->block_length=0; \
|
||||
create_block: \
|
||||
ar->values[ar->blocks_count]=malloc(ar->max_block_length*typesize(ar->type)); \
|
||||
ar->blocks_count++; \
|
||||
} \
|
||||
ar->values[ar->blocks_count-1][ar->block_length]=element; \
|
||||
ar->block_length++; \
|
||||
} \
|
||||
\
|
||||
type Autoarr_get_##type(struct Autoarr_##type* ar, uint32 index){ \
|
||||
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
||||
return ar->values[index/ar->max_block_length][index%ar->max_block_length]; \
|
||||
} \
|
||||
\
|
||||
void Autoarr_set_##type(struct Autoarr_##type* ar, uint32 index, type element){ \
|
||||
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
|
||||
ar->values[index/ar->max_block_length][index%ar->max_block_length]=element; \
|
||||
} \
|
||||
\
|
||||
Autoarr_##type Autoarr_create_##type(uint16 max_blocks_count, uint16 max_block_length){ \
|
||||
return (Autoarr_##type)={ \
|
||||
.max_blocks_count=max_blocks_count, \
|
||||
.blocks_count=0, \
|
||||
.max_block_length=max_block_length, \
|
||||
.block_length=0, \
|
||||
.values=NULL, \
|
||||
.Autoarr_add=Autoarr_add_##type, \
|
||||
.Autoarr_get=Autoarr_get_##type, \
|
||||
.Autoarr_set=Autoarr_set_##type \
|
||||
}; \
|
||||
} \
|
||||
\
|
||||
void Autoarr_clear_##type(Autoarr_##type ar){ \
|
||||
for(uint16 i=0; i<ar->blocks_count;i++) \
|
||||
free(ar->values[i]); \
|
||||
free(ar->values); \
|
||||
ar->values=NULL; \
|
||||
ar->blocks_count=0; \
|
||||
ar->block_length=0; \
|
||||
}
|
||||
|
||||
#define Autoarr(type) Autoarr_##type
|
||||
#define Autoarr_create(type, max_blocks_count, max_block_length) \
|
||||
Autoarr_create_##type(max_blocks_count, max_block_length)
|
||||
@ -1,26 +1,24 @@
|
||||
#include "Hashtable.h"
|
||||
|
||||
/*
|
||||
Hashtable Hashtable_create(uint16 height){
|
||||
Hashtable h={
|
||||
.height=height,
|
||||
.rows=malloc(height*sizeof(Autoarr*))
|
||||
.rows=malloc(height*sizeof(Autoarr))
|
||||
};
|
||||
return h;
|
||||
}
|
||||
|
||||
void Hashtable_clear(Hashtable* ht){
|
||||
for(uint16 i=0;i<ht->height;i++)
|
||||
Autoarr_clear(ht->rows[i]);
|
||||
free(ht->rows);
|
||||
Autoarr_clear(ht->rows+i);
|
||||
}
|
||||
|
||||
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});
|
||||
}
|
||||
*/
|
||||
@ -6,10 +6,10 @@
|
||||
|
||||
typedef struct Hashtable{
|
||||
uint16 height; // amount of rows
|
||||
Autoarr** rows; // Autoarr[height]s
|
||||
Autoarr* rows; // Autoarr[height]s
|
||||
} Hashtable;
|
||||
|
||||
Hashtable Hashtable_create(uint16 height,my_type type);
|
||||
Hashtable Hashtable_create(uint16 height);
|
||||
|
||||
void Hashtable_clear(Hashtable* ht);
|
||||
|
||||
@ -22,4 +22,4 @@ 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;
|
||||
const uint16 Hashtable_HMAX=65521;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "SearchTree.h"
|
||||
#include "../Autoarr/Autoarr.h"
|
||||
|
||||
STNode* STNode_create(){
|
||||
STNode* node=malloc(sizeof(STNode));
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#include "base/base.h"
|
||||
#include "tests/tests.h"
|
||||
#include "Autoarr/Autoarr.h"
|
||||
#include "SearchTree/SearchTree.h"
|
||||
#include "Hashtable/hash.h"
|
||||
|
||||
|
||||
int main(){
|
||||
setlocale(LC_ALL, "en-US.Unicode");
|
||||
printf("\e[92mdtsod parser in c language!\e[97m\n");
|
||||
|
||||
17
DtsodC/src/tests/new.c
Normal file
17
DtsodC/src/tests/new.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "new.h"
|
||||
#include "../Autoarr/new.h"
|
||||
#include "../base/base.h"
|
||||
|
||||
define_Autoarr(uint16)
|
||||
|
||||
void test_new(){
|
||||
printf("\e[96m------------[test_autoarr]-------------\n");
|
||||
Autoarr(uint16) ar=Autoarr_create(uint16,10,16);
|
||||
printf("\e[92mautoarr created\n\e[90m");
|
||||
fillar(&ar);
|
||||
printallval(&ar);
|
||||
printf("\n\e[92mautoarr filled up\n");
|
||||
printautoarr(&ar);
|
||||
Autoarr_clear(&ar);
|
||||
printf("\e[92mautoarr cleared\n");
|
||||
}
|
||||
1
DtsodC/src/tests/new.h
Normal file
1
DtsodC/src/tests/new.h
Normal file
@ -0,0 +1 @@
|
||||
void test_new();
|
||||
Loading…
Reference in New Issue
Block a user