76
This commit is contained in:
parent
a25f5bd5f1
commit
1650733daa
@ -1,3 +1,8 @@
|
||||
#include "../base/base.h"
|
||||
|
||||
#ifndef AUTOARR_H
|
||||
#define AUTOARR_H
|
||||
|
||||
#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)
|
||||
|
||||
@ -13,35 +18,34 @@ typedef struct Autoarr_##type{ \
|
||||
void (*Autoarr_set)(struct Autoarr_##type* ar, uint32 index, type element); \
|
||||
} Autoarr_##type; \
|
||||
\
|
||||
void Autoarr_add_##type(struct Autoarr_##type* ar, type element){ \
|
||||
void Autoarr_add_##type(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->values[ar->blocks_count]=malloc(ar->max_block_length*sizeof(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){ \
|
||||
type Autoarr_get_##type(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){ \
|
||||
void Autoarr_set_##type(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)={ \
|
||||
return (Autoarr_##type){ \
|
||||
.max_blocks_count=max_blocks_count, \
|
||||
.blocks_count=0, \
|
||||
.max_block_length=max_block_length, \
|
||||
@ -53,7 +57,7 @@ Autoarr_##type Autoarr_create_##type(uint16 max_blocks_count, uint16 max_block_l
|
||||
}; \
|
||||
} \
|
||||
\
|
||||
void Autoarr_clear_##type(Autoarr_##type ar){ \
|
||||
void Autoarr_clear_##type(Autoarr_##type* ar){ \
|
||||
for(uint16 i=0; i<ar->blocks_count;i++) \
|
||||
free(ar->values[i]); \
|
||||
free(ar->values); \
|
||||
@ -65,3 +69,5 @@ void Autoarr_clear_##type(Autoarr_##type ar){ \
|
||||
#define Autoarr(type) Autoarr_##type
|
||||
#define Autoarr_create(type, max_blocks_count, max_block_length) \
|
||||
Autoarr_create_##type(max_blocks_count, max_block_length)
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
#include "base/base.h"
|
||||
#include "tests/tests.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");
|
||||
test_all();
|
||||
//test_all();
|
||||
test_new();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,8 +1,37 @@
|
||||
#include "new.h"
|
||||
#include "tests.h"
|
||||
#include "../Autoarr/new.h"
|
||||
#include "../base/base.h"
|
||||
|
||||
#ifndef Aaaa
|
||||
#define Aaaa
|
||||
define_Autoarr(uint16)
|
||||
#endif
|
||||
|
||||
void printautoarr(Autoarr(uint16)* ar){
|
||||
printf("\e[94mAUTOARR:%lu\n"
|
||||
" max_blocks_count: %u\n"
|
||||
" blocks_count: %u\n"
|
||||
" max_block_length: %u\n"
|
||||
" block_length: %u\n"
|
||||
" max_length: %u\n"
|
||||
" length: %u\n",
|
||||
sizeof(Autoarr(uint16)),
|
||||
ar->max_blocks_count,
|
||||
ar->blocks_count,
|
||||
ar->max_block_length,
|
||||
ar->block_length,
|
||||
Autoarr_max_length(ar),
|
||||
Autoarr_length(ar));
|
||||
}
|
||||
|
||||
void fillar(Autoarr(uint16)* ar){
|
||||
for (uint16 i=0;i<Autoarr_max_length(ar);i++)
|
||||
Autoarr_add_uint16(ar,i);
|
||||
}
|
||||
|
||||
void printallval(Autoarr(uint16)* ar){
|
||||
for (uint16 i=0;i<Autoarr_max_length(ar);i++)
|
||||
printf("%u ", Autoarr_get_uint16(ar,i));
|
||||
}
|
||||
|
||||
void test_new(){
|
||||
printf("\e[96m------------[test_autoarr]-------------\n");
|
||||
@ -12,6 +41,6 @@ void test_new(){
|
||||
printallval(&ar);
|
||||
printf("\n\e[92mautoarr filled up\n");
|
||||
printautoarr(&ar);
|
||||
Autoarr_clear(&ar);
|
||||
Autoarr_clear_uint16(&ar);
|
||||
printf("\e[92mautoarr cleared\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
void test_new();
|
||||
@ -1,14 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "../base/std.h"
|
||||
#include "../SearchTree/SearchTree.h"
|
||||
#include "../Autoarr/Autoarr.h"
|
||||
#include "../base/base.h"
|
||||
|
||||
void test_autoarr(void);
|
||||
void printautoarr(Autoarr* ar);
|
||||
|
||||
void test_searchtree(void);
|
||||
void printstnode(STNode* node);
|
||||
void printuni(Unitype v);
|
||||
|
||||
void test_autoarr(void);
|
||||
void test_searchtree(void);
|
||||
void test_all(void);
|
||||
void test_new(void);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user