changed Autoarr field names
This commit is contained in:
parent
61da9ad161
commit
490d450a82
@ -24,15 +24,15 @@ Autoarr_declare(u64)
|
||||
Autoarr_declare(Unitype)
|
||||
|
||||
#define Autoarr_foreach(ar, elem, codeblock...) { \
|
||||
if(ar->blocks_count>0) { \
|
||||
typeof(**ar->values) elem; \
|
||||
for(u16 blockI=0;blockI<ar->blocks_count-1;blockI++) \
|
||||
for(u32 elemI=0;elemI<ar->max_block_length;elemI++){ \
|
||||
elem=ar->values[blockI][elemI]; \
|
||||
if(ar->chunks_count>0) { \
|
||||
typeof(**ar->chunks) elem; \
|
||||
for(u16 chunkI=0;chunkI<ar->chunks_count-1;chunkI++) \
|
||||
for(u32 elemI=0;elemI<ar->max_chunk_length;elemI++){ \
|
||||
elem=ar->chunks[chunkI][elemI]; \
|
||||
{ codeblock; } \
|
||||
} \
|
||||
for(u16 elemI=0;elemI<ar->block_length;elemI++){ \
|
||||
elem=ar->values[ar->blocks_count-1][elemI]; \
|
||||
for(u16 elemI=0;elemI<ar->chunk_length;elemI++){ \
|
||||
elem=ar->chunks[ar->chunks_count-1][elemI]; \
|
||||
{ codeblock; } \
|
||||
} \
|
||||
} \
|
||||
|
||||
@ -5,8 +5,8 @@ extern "C" {
|
||||
#include "Autoarr.h"
|
||||
#include "../Hashtable/KeyValuePair.h"
|
||||
|
||||
EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_blocks_count, u16 max_block_length, Autoarr_KVPair** output){
|
||||
*output=Autoarr_create(KVPair, max_blocks_count, max_block_length);
|
||||
EXPORT void CALL kerep_Autoarr_KVPair_create(u16 max_chunks_count, u16 max_chunk_length, Autoarr_KVPair** output){
|
||||
*output=Autoarr_create(KVPair, max_chunks_count, max_chunk_length);
|
||||
}
|
||||
|
||||
EXPORT void CALL kerep_Autoarr_KVPair_free(Autoarr_KVPair* ar){
|
||||
|
||||
@ -4,8 +4,8 @@ extern "C" {
|
||||
|
||||
#include "Autoarr.h"
|
||||
|
||||
EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_blocks_count, u16 max_block_length, Autoarr_Unitype** output){
|
||||
*output=Autoarr_create(Unitype, max_blocks_count, max_block_length);
|
||||
EXPORT void CALL kerep_Autoarr_Unitype_create(u16 max_chunks_count, u16 max_chunk_length, Autoarr_Unitype** output){
|
||||
*output=Autoarr_create(Unitype, max_chunks_count, max_chunk_length);
|
||||
}
|
||||
|
||||
EXPORT void CALL kerep_Autoarr_Unitype_free(Autoarr_Unitype* ar){
|
||||
|
||||
@ -23,22 +23,22 @@ typedef struct __Autoarr_##type##_functions_list_t { \
|
||||
extern __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list; \
|
||||
\
|
||||
STRUCT(Autoarr_##type, \
|
||||
u16 blocks_count; \
|
||||
u16 max_blocks_count; \
|
||||
u16 block_length; \
|
||||
u16 max_block_length; \
|
||||
type** values; \
|
||||
u16 chunks_count; \
|
||||
u16 max_chunks_count; \
|
||||
u16 chunk_length; \
|
||||
u16 max_chunk_length; \
|
||||
type** chunks; \
|
||||
__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(void* ar);
|
||||
|
||||
#define Autoarr(type) Autoarr_##type
|
||||
|
||||
#define Autoarr_create(type, max_blocks_count, max_block_length) \
|
||||
__Autoarr_##type##_create(max_blocks_count, max_block_length)
|
||||
#define Autoarr_create(type, max_chunks_count, max_chunk_length) \
|
||||
__Autoarr_##type##_create(max_chunks_count, max_chunk_length)
|
||||
#define Autoarr_add(autoarr, element) \
|
||||
autoarr->functions->add(autoarr, element)
|
||||
#define Autoarr_get(autoarr, index) \
|
||||
@ -55,18 +55,18 @@ void ____Autoarr_##type##_freeWithMembers(void* ar);
|
||||
autoarr->functions->toArray(autoarr)
|
||||
|
||||
#define Autoarr_length(autoarr) \
|
||||
(u32)(!autoarr->blocks_count ? 0 : \
|
||||
autoarr->max_block_length*(autoarr->blocks_count-1)+autoarr->block_length)
|
||||
(u32)(!autoarr->chunks_count ? 0 : \
|
||||
autoarr->max_chunk_length*(autoarr->chunks_count-1)+autoarr->chunk_length)
|
||||
#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){ \
|
||||
if(AR->block_length==1){ \
|
||||
AR->blocks_count--; \
|
||||
AR->block_length=AR->max_block_length; \
|
||||
free(AR->values[AR->blocks_count]); \
|
||||
if(AR->chunk_length==1){ \
|
||||
AR->chunks_count--; \
|
||||
AR->chunk_length=AR->max_chunk_length; \
|
||||
free(AR->chunks[AR->chunks_count]); \
|
||||
} \
|
||||
else AR->block_length--; \
|
||||
else AR->chunk_length--; \
|
||||
}
|
||||
|
||||
#if __cplusplus
|
||||
|
||||
@ -11,40 +11,40 @@ extern "C" {
|
||||
kt_define(Autoarr_##type, ____Autoarr_##type##_freeWithMembers, NULL); \
|
||||
\
|
||||
void __Autoarr_##type##_add(Autoarr_##type* ar, type element){ \
|
||||
if(!ar->values){ \
|
||||
ar->values=malloc(ar->max_blocks_count*sizeof(type*)); \
|
||||
goto create_block; \
|
||||
if(!ar->chunks){ \
|
||||
ar->chunks=malloc(ar->max_chunks_count*sizeof(type*)); \
|
||||
goto create_chunk; \
|
||||
} \
|
||||
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*sizeof(type)); \
|
||||
ar->blocks_count++; \
|
||||
if(ar->chunk_length==ar->max_chunk_length){ \
|
||||
if (ar->chunks_count>=ar->max_chunks_count) throw(ERR_MAXLENGTH); \
|
||||
ar->chunk_length=0; \
|
||||
create_chunk: \
|
||||
ar->chunks[ar->chunks_count]=malloc(ar->max_chunk_length*sizeof(type)); \
|
||||
ar->chunks_count++; \
|
||||
} \
|
||||
ar->values[ar->blocks_count-1][ar->block_length]=element; \
|
||||
ar->block_length++; \
|
||||
ar->chunks[ar->chunks_count-1][ar->chunk_length]=element; \
|
||||
ar->chunk_length++; \
|
||||
} \
|
||||
\
|
||||
type __Autoarr_##type##_get(Autoarr_##type* ar, u32 index){ \
|
||||
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){ \
|
||||
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){ \
|
||||
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){ \
|
||||
for(u16 i=0; i<ar->blocks_count;i++) \
|
||||
free(ar->values[i]); \
|
||||
free(ar->values); \
|
||||
for(u16 i=0; i<ar->chunks_count;i++) \
|
||||
free(ar->chunks[i]); \
|
||||
free(ar->chunks); \
|
||||
if(freePtr) free(ar); \
|
||||
} \
|
||||
\
|
||||
@ -82,14 +82,14 @@ __Autoarr_##type##_functions_list_t __Autoarr_##type##_functions_list={ \
|
||||
&__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)); \
|
||||
*ar=(Autoarr_##type){ \
|
||||
.max_blocks_count=max_blocks_count, \
|
||||
.blocks_count=0, \
|
||||
.max_block_length=max_block_length, \
|
||||
.block_length=0, \
|
||||
.values=NULL, \
|
||||
.max_chunks_count=max_chunks_count, \
|
||||
.chunks_count=0, \
|
||||
.max_chunk_length=max_chunk_length, \
|
||||
.chunk_length=0, \
|
||||
.chunks=NULL, \
|
||||
.functions=&__Autoarr_##type##_functions_list \
|
||||
}; \
|
||||
return ar; \
|
||||
|
||||
@ -22,7 +22,7 @@ void 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);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ string StringBuilder_build(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)
|
||||
else {
|
||||
if(!b->compl_bufs) throw(ERR_NULLPTR);
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
#include "../src/Autoarr/Autoarr.h"
|
||||
#include <vector>
|
||||
|
||||
i64 _autoarrVsVector(u16 blockCount, u16 blockLength){
|
||||
u32 count=blockLength*blockCount;
|
||||
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (u64)count);
|
||||
Autoarr_i64* ar=Autoarr_create(i64, blockCount, blockLength);
|
||||
i64 _autoarrVsVector(u16 chunkCount, u16 chunkLength){
|
||||
u32 count=chunkLength*chunkCount;
|
||||
kprintf("\e[94mchunk count: %u chunk length: %u count: " IFWIN("%llu", "%lu") "\n", chunkCount, chunkLength, (u64)count);
|
||||
Autoarr_i64* ar=Autoarr_create(i64, chunkCount, chunkLength);
|
||||
std::vector<i64> vec=std::vector<i64>();
|
||||
optime("Autoarr_add", count,
|
||||
Autoarr_add(ar, op_i));
|
||||
|
||||
@ -4,17 +4,17 @@
|
||||
static void printautoarr(Autoarr(u16)* ar){
|
||||
kprintf("\e[94mAutoarr(u16): "
|
||||
IFWIN("%llu", "%lu")
|
||||
"\n max_blocks_count: %u\n"
|
||||
" blocks_count: %u\n"
|
||||
" max_block_length: %u\n"
|
||||
" block_length: %u\n"
|
||||
"\n max_chunks_count: %u\n"
|
||||
" chunks_count: %u\n"
|
||||
" max_chunk_length: %u\n"
|
||||
" chunk_length: %u\n"
|
||||
" max_length: %u\n"
|
||||
" length: %u\n",
|
||||
sizeof(Autoarr(u16)),
|
||||
ar->max_blocks_count,
|
||||
ar->blocks_count,
|
||||
ar->max_block_length,
|
||||
ar->block_length,
|
||||
ar->max_chunks_count,
|
||||
ar->chunks_count,
|
||||
ar->max_chunk_length,
|
||||
ar->chunk_length,
|
||||
Autoarr_max_length(ar),
|
||||
Autoarr_length(ar));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user