changed Autoarr field names

This commit is contained in:
timerix 2023-06-05 13:56:14 +06:00
parent 61da9ad161
commit 490d450a82
8 changed files with 64 additions and 64 deletions

View File

@ -24,15 +24,15 @@ Autoarr_declare(u64)
Autoarr_declare(Unitype) Autoarr_declare(Unitype)
#define Autoarr_foreach(ar, elem, codeblock...) { \ #define Autoarr_foreach(ar, elem, codeblock...) { \
if(ar->blocks_count>0) { \ if(ar->chunks_count>0) { \
typeof(**ar->values) elem; \ typeof(**ar->chunks) elem; \
for(u16 blockI=0;blockI<ar->blocks_count-1;blockI++) \ for(u16 chunkI=0;chunkI<ar->chunks_count-1;chunkI++) \
for(u32 elemI=0;elemI<ar->max_block_length;elemI++){ \ for(u32 elemI=0;elemI<ar->max_chunk_length;elemI++){ \
elem=ar->values[blockI][elemI]; \ elem=ar->chunks[chunkI][elemI]; \
{ codeblock; } \ { codeblock; } \
} \ } \
for(u16 elemI=0;elemI<ar->block_length;elemI++){ \ for(u16 elemI=0;elemI<ar->chunk_length;elemI++){ \
elem=ar->values[ar->blocks_count-1][elemI]; \ elem=ar->chunks[ar->chunks_count-1][elemI]; \
{ codeblock; } \ { codeblock; } \
} \ } \
} \ } \

View File

@ -5,8 +5,8 @@ extern "C" {
#include "Autoarr.h" #include "Autoarr.h"
#include "../Hashtable/KeyValuePair.h" #include "../Hashtable/KeyValuePair.h"
EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_blocks_count, u16 max_block_length, Autoarr_KVPair** output){ EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_chunks_count, u16 max_chunk_length, Autoarr_KVPair** output){
*output=Autoarr_create(KVPair, max_blocks_count, max_block_length); *output=Autoarr_create(KVPair, max_chunks_count, max_chunk_length);
} }
EXPORT void CALL kerep_Autoarr_KVPair_free(Autoarr_KVPair* ar){ EXPORT void CALL kerep_Autoarr_KVPair_free(Autoarr_KVPair* ar){

View File

@ -4,8 +4,8 @@ extern "C" {
#include "Autoarr.h" #include "Autoarr.h"
EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_blocks_count, u16 max_block_length, Autoarr_Unitype** output){ EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_chunks_count, u16 max_chunk_length, Autoarr_Unitype** output){
*output=Autoarr_create(Unitype, max_blocks_count, max_block_length); *output=Autoarr_create(Unitype, max_chunks_count, max_chunk_length);
} }
EXPORT void CALL kerep_Autoarr_Unitype_free(Autoarr_Unitype* ar){ EXPORT void CALL kerep_Autoarr_Unitype_free(Autoarr_Unitype* ar){

View File

@ -23,22 +23,22 @@ typedef struct __Autoarr_##type##_functions_list_t { \
extern __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list; \ extern __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list; \
\ \
STRUCT(Autoarr_##type, \ STRUCT(Autoarr_##type, \
u16 blocks_count; \ u16 chunks_count; \
u16 max_blocks_count; \ u16 max_chunks_count; \
u16 block_length; \ u16 chunk_length; \
u16 max_block_length; \ u16 max_chunk_length; \
type** values; \ type** chunks; \
__Autoarr_##type##_functions_list_t* functions; \ __Autoarr_##type##_functions_list_t* functions; \
) \ ) \
\ \
Autoarr_##type* __Autoarr_##type##_create(u16 max_blocks_count, u16 max_block_length); \ Autoarr_##type* __Autoarr_##type##_create(u16 max_chunks_count, u16 max_chunk_length); \
void __Autoarr_##type##_freeWithMembers(Autoarr_##type* ar, bool freePtr); \ void __Autoarr_##type##_freeWithMembers(Autoarr_##type* ar, bool freePtr); \
void ____Autoarr_##type##_freeWithMembers(void* ar); void ____Autoarr_##type##_freeWithMembers(void* ar);
#define Autoarr(type) Autoarr_##type #define Autoarr(type) Autoarr_##type
#define Autoarr_create(type, max_blocks_count, max_block_length) \ #define Autoarr_create(type, max_chunks_count, max_chunk_length) \
__Autoarr_##type##_create(max_blocks_count, max_block_length) __Autoarr_##type##_create(max_chunks_count, max_chunk_length)
#define Autoarr_add(autoarr, element) \ #define Autoarr_add(autoarr, element) \
autoarr->functions->add(autoarr, element) autoarr->functions->add(autoarr, element)
#define Autoarr_get(autoarr, index) \ #define Autoarr_get(autoarr, index) \
@ -55,18 +55,18 @@ void ____Autoarr_##type##_freeWithMembers(void* ar);
autoarr->functions->toArray(autoarr) autoarr->functions->toArray(autoarr)
#define Autoarr_length(autoarr) \ #define Autoarr_length(autoarr) \
(u32)(!autoarr->blocks_count ? 0 : \ (u32)(!autoarr->chunks_count ? 0 : \
autoarr->max_block_length*(autoarr->blocks_count-1)+autoarr->block_length) autoarr->max_chunk_length*(autoarr->chunks_count-1)+autoarr->chunk_length)
#define Autoarr_max_length(autoarr) \ #define Autoarr_max_length(autoarr) \
(u32)(autoarr->max_block_length*autoarr->max_blocks_count) (u32)(autoarr->max_chunk_length*autoarr->max_chunks_count)
#define Autoarr_pop(AR){ \ #define Autoarr_pop(AR){ \
if(AR->block_length==1){ \ if(AR->chunk_length==1){ \
AR->blocks_count--; \ AR->chunks_count--; \
AR->block_length=AR->max_block_length; \ AR->chunk_length=AR->max_chunk_length; \
free(AR->values[AR->blocks_count]); \ free(AR->chunks[AR->chunks_count]); \
} \ } \
else AR->block_length--; \ else AR->chunk_length--; \
} }
#if __cplusplus #if __cplusplus

View File

@ -11,40 +11,40 @@ extern "C" {
kt_define(Autoarr_##type, ____Autoarr_##type##_freeWithMembers, NULL); \ kt_define(Autoarr_##type, ____Autoarr_##type##_freeWithMembers, NULL); \
\ \
void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \ void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \
if(!ar->values){ \ if(!ar->chunks){ \
ar->values=malloc(ar->max_blocks_count*sizeof(type*)); \ ar->chunks=malloc(ar->max_chunks_count*sizeof(type*)); \
goto create_block; \ goto create_chunk; \
} \ } \
if(ar->block_length==ar->max_block_length){ \ if(ar->chunk_length==ar->max_chunk_length){ \
if (ar->blocks_count>=ar->max_blocks_count) throw(ERR_MAXLENGTH); \ if (ar->chunks_count>=ar->max_chunks_count) throw(ERR_MAXLENGTH); \
ar->block_length=0; \ ar->chunk_length=0; \
create_block: \ create_chunk: \
ar->values[ar->blocks_count]=malloc(ar->max_block_length*sizeof(type)); \ ar->chunks[ar->chunks_count]=malloc(ar->max_chunk_length*sizeof(type)); \
ar->blocks_count++; \ ar->chunks_count++; \
} \ } \
ar->values[ar->blocks_count-1][ar->block_length]=element; \ ar->chunks[ar->chunks_count-1][ar->chunk_length]=element; \
ar->block_length++; \ ar->chunk_length++; \
} \ } \
\ \
type __Autoarr_##type##_get(Autoarr_##type* ar, u32 index){ \ type __Autoarr_##type##_get(Autoarr_##type* ar, u32 index){ \
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \ if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
return ar->values[index/ar->max_block_length][index%ar->max_block_length]; \ return ar->chunks[index/ar->max_chunk_length][index%ar->max_chunk_length]; \
} \ } \
\ \
type* __Autoarr_##type##_getPtr(Autoarr_##type* ar, u32 index){ \ type* __Autoarr_##type##_getPtr(Autoarr_##type* ar, u32 index){ \
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \ if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
return ar->values[index/ar->max_block_length]+(index%ar->max_block_length); \ return ar->chunks[index/ar->max_chunk_length]+(index%ar->max_chunk_length); \
} \ } \
\ \
void __Autoarr_##type##_set(Autoarr_##type* ar, u32 index, type element){ \ void __Autoarr_##type##_set(Autoarr_##type* ar, u32 index, type element){ \
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \ if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX); \
ar->values[index/ar->max_block_length][index%ar->max_block_length]=element; \ ar->chunks[index/ar->max_chunk_length][index%ar->max_chunk_length]=element; \
} \ } \
\ \
void __Autoarr_##type##_freeWithoutMembers(Autoarr_##type* ar, bool freePtr){ \ void __Autoarr_##type##_freeWithoutMembers(Autoarr_##type* ar, bool freePtr){ \
for(u16 i=0; i<ar->blocks_count;i++) \ for(u16 i=0; i<ar->chunks_count;i++) \
free(ar->values[i]); \ free(ar->chunks[i]); \
free(ar->values); \ free(ar->chunks); \
if(freePtr) free(ar); \ if(freePtr) free(ar); \
} \ } \
\ \
@ -82,14 +82,14 @@ __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list={ \
&__Autoarr_##type##_toArray \ &__Autoarr_##type##_toArray \
}; \ }; \
\ \
Autoarr_##type* __Autoarr_##type##_create(u16 max_blocks_count, u16 max_block_length){ \ Autoarr_##type* __Autoarr_##type##_create(u16 max_chunks_count, u16 max_chunk_length){ \
Autoarr_##type* ar=malloc(sizeof(Autoarr_##type)); \ Autoarr_##type* ar=malloc(sizeof(Autoarr_##type)); \
*ar=(Autoarr_##type){ \ *ar=(Autoarr_##type){ \
.max_blocks_count=max_blocks_count, \ .max_chunks_count=max_chunks_count, \
.blocks_count=0, \ .chunks_count=0, \
.max_block_length=max_block_length, \ .max_chunk_length=max_chunk_length, \
.block_length=0, \ .chunk_length=0, \
.values=NULL, \ .chunks=NULL, \
.functions=&__Autoarr_##type##_functions_list \ .functions=&__Autoarr_##type##_functions_list \
}; \ }; \
return ar; \ return ar; \

View File

@ -22,7 +22,7 @@ void complete_buf(StringBuilder* b){
} }
void try_complete_buf(StringBuilder* b){ void try_complete_buf(StringBuilder* b){
if(b->curr_buf->blocks_count==BL_C) if(b->curr_buf->chunks_count==BL_C)
complete_buf(b); complete_buf(b);
} }
@ -64,7 +64,7 @@ string StringBuilder_build(StringBuilder* b){
void StringBuilder_rmchar(StringBuilder* b){ void StringBuilder_rmchar(StringBuilder* b){
if(b->curr_buf->block_length!=0) if(b->curr_buf->chunk_length!=0)
Autoarr_pop(b->curr_buf) Autoarr_pop(b->curr_buf)
else { else {
if(!b->compl_bufs) throw(ERR_NULLPTR); if(!b->compl_bufs) throw(ERR_NULLPTR);

View File

@ -2,10 +2,10 @@
#include "../src/Autoarr/Autoarr.h" #include "../src/Autoarr/Autoarr.h"
#include <vector> #include <vector>
i64 _autoarrVsVector(u16 blockCount, u16 blockLength){ i64 _autoarrVsVector(u16 chunkCount, u16 chunkLength){
u32 count=blockLength*blockCount; u32 count=chunkLength*chunkCount;
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (u64)count); kprintf("\e[94mchunk count: %u chunk length: %u count: " IFWIN("%llu", "%lu") "\n", chunkCount, chunkLength, (u64)count);
Autoarr_i64* ar=Autoarr_create(i64, blockCount, blockLength); Autoarr_i64* ar=Autoarr_create(i64, chunkCount, chunkLength);
std::vector<i64> vec=std::vector<i64>(); std::vector<i64> vec=std::vector<i64>();
optime("Autoarr_add", count, optime("Autoarr_add", count,
Autoarr_add(ar, op_i)); Autoarr_add(ar, op_i));

View File

@ -4,17 +4,17 @@
static void printautoarr(Autoarr(u16)* ar){ static void printautoarr(Autoarr(u16)* ar){
kprintf("\e[94mAutoarr(u16): " kprintf("\e[94mAutoarr(u16): "
IFWIN("%llu", "%lu") IFWIN("%llu", "%lu")
"\n max_blocks_count: %u\n" "\n max_chunks_count: %u\n"
" blocks_count: %u\n" " chunks_count: %u\n"
" max_block_length: %u\n" " max_chunk_length: %u\n"
" block_length: %u\n" " chunk_length: %u\n"
" max_length: %u\n" " max_length: %u\n"
" length: %u\n", " length: %u\n",
sizeof(Autoarr(u16)), sizeof(Autoarr(u16)),
ar->max_blocks_count, ar->max_chunks_count,
ar->blocks_count, ar->chunks_count,
ar->max_block_length, ar->max_chunk_length,
ar->block_length, ar->chunk_length,
Autoarr_max_length(ar), Autoarr_max_length(ar),
Autoarr_length(ar)); Autoarr_length(ar));
} }