From 305854e72108f1af474dfbea1e8cd0d941d619c6 Mon Sep 17 00:00:00 2001 From: timerix Date: Sat, 11 Feb 2023 12:19:05 +0600 Subject: [PATCH] i32 --- src/Array/Array.c | 22 ++--- src/Array/Array.h | 20 ++-- src/Array/Array_declare.h | 6 +- src/Autoarr/Autoarr.c | 20 ++-- src/Autoarr/Autoarr.h | 20 ++-- src/Autoarr/Autoarr_KVPair_exported.c | 10 +- src/Autoarr/Autoarr_Unitype.h | 6 +- src/Autoarr/Autoarr_Unitype_exported.c | 10 +- src/Autoarr/Autoarr_declare.h | 20 ++-- src/Autoarr/Autoarr_define.h | 14 +-- src/DtsodParser/DtsodV24_deserialize.c | 12 +-- src/DtsodParser/DtsodV24_exported.c | 4 +- src/DtsodParser/DtsodV24_serialize.c | 20 ++-- src/Filesystem/dir.c | 2 +- src/Filesystem/file.c | 24 ++--- src/Filesystem/file.h | 8 +- src/Filesystem/path.c | 16 ++-- src/Filesystem/path.h | 2 +- src/HashFunctions/hash.c | 20 ++-- src/HashFunctions/hash.h | 4 +- src/Hashtable/Hashtable.c | 28 +++--- src/Hashtable/Hashtable.h | 8 +- src/SearchTree/SearchTree.c | 20 ++-- src/String/StringBuilder.c | 26 ++--- src/String/StringBuilder.h | 8 +- src/String/string.c | 4 +- src/String/string.h | 2 +- src/base/cptr.c | 42 ++++----- src/base/cptr.h | 16 ++-- src/base/endian.c | 2 +- src/base/errors.c | 4 +- src/base/errors.h | 4 +- src/base/optime.h | 12 +-- src/base/std.h | 23 ++--- src/base/type_system/base_toString.c | 94 +++++++++---------- src/base/type_system/base_toString.h | 40 ++++---- src/base/type_system/init.c | 60 ++++++------ src/base/type_system/ktDescriptor.h | 4 +- src/base/type_system/kt_functions.c | 22 ++--- src/base/type_system/kt_functions.h | 22 ++--- src/base/type_system/ktid.h | 2 +- src/base/type_system/unitype.c | 8 +- src/base/type_system/unitype.h | 12 +-- src/kprint/README.md | 20 ++-- src/kprint/kprint.c | 28 +++--- src/kprint/kprint.h | 24 ++--- src/kprint/kprint_format.h | 2 +- src/kprint/kprint_format.md | 20 ++-- src/kprint/kprintf.c | 22 ++--- src/random/krandom.h | 18 ++-- src/random/splitmix64/splitmix64.c | 6 +- src/random/splitmix64/splitmix64.h | 6 +- src/random/xoroshiro/32bitValue/xoroshiro64.h | 10 +- .../xoroshiro/32bitValue/xoroshiro64star.c | 16 ++-- .../32bitValue/xoroshiro64starstar.c | 10 +- .../xoroshiro/64bitValue/xoroshiro128.h | 10 +- .../xoroshiro/64bitValue/xoroshiro128plus.c | 16 ++-- .../64bitValue/xoroshiro128plusplus.c | 12 +-- .../64bitValue/xoroshiro128starstar.c | 12 +-- src/random/xoshiro/32bitValue/xoshiro128.h | 12 +-- .../xoshiro/32bitValue/xoshiro128plus.c | 14 +-- .../xoshiro/32bitValue/xoshiro128plusplus.c | 8 +- .../xoshiro/32bitValue/xoshiro128starstar.c | 8 +- src/random/xoshiro/64bitValue/xoshiro256.h | 10 +- .../xoshiro/64bitValue/xoshiro256plus.c | 10 +- .../xoshiro/64bitValue/xoshiro256plusplus.c | 10 +- .../xoshiro/64bitValue/xoshiro256starstar.c | 10 +- tests/main.cpp | 2 +- tests/test_autoarr-vs-vector.cpp | 12 +-- tests/test_autoarr.c | 20 ++-- tests/test_dtsod.c | 4 +- tests/test_hash_functions.c | 12 +-- tests/test_hashtable.c | 18 ++-- tests/test_kprint.c | 4 +- tests/test_kprint_colors.c | 4 +- tests/test_rng_algorithms.c | 8 +- tests/test_searchtree.c | 6 +- 77 files changed, 565 insertions(+), 562 deletions(-) diff --git a/src/Array/Array.c b/src/Array/Array.c index e6b3069..c6a3145 100644 --- a/src/Array/Array.c +++ b/src/Array/Array.c @@ -2,21 +2,21 @@ Array_define(char) Array_define(bool) -Array_define(float32) -Array_define(float64) -Array_define(int8) -Array_define(uint8) -Array_define(int16) -Array_define(uint16) -Array_define(int32) -Array_define(uint32) -Array_define(int64) -Array_define(uint64) +Array_define(f32) +Array_define(f64) +Array_define(i8) +Array_define(u8) +Array_define(i16) +Array_define(u16) +Array_define(i32) +Array_define(u32) +Array_define(i64) +Array_define(u64) Array_define(Unitype) void Array_Unitype_free_(Array_Unitype* array, bool freeMembers){ - if(freeMembers) for (int32 i=0; ilength; i++) + if(freeMembers) for (i32 i=0; ilength; i++) Unitype_free(array->values[i]); if(array->allocatedOnHeap) free(array->values); diff --git a/src/Array/Array.h b/src/Array/Array.h index 5c8f388..31b00f6 100644 --- a/src/Array/Array.h +++ b/src/Array/Array.h @@ -9,16 +9,16 @@ extern "C" { Array_declare(char) Array_declare(bool) -Array_declare(float32) -Array_declare(float64) -Array_declare(int8) -Array_declare(uint8) -Array_declare(int16) -Array_declare(uint16) -Array_declare(int32) -Array_declare(uint32) -Array_declare(int64) -Array_declare(uint64) +Array_declare(f32) +Array_declare(f64) +Array_declare(i8) +Array_declare(u8) +Array_declare(i16) +Array_declare(u16) +Array_declare(i32) +Array_declare(u32) +Array_declare(i64) +Array_declare(u64) Array_declare(Unitype) diff --git a/src/Array/Array_declare.h b/src/Array/Array_declare.h index 2c7a37f..089874d 100644 --- a/src/Array/Array_declare.h +++ b/src/Array/Array_declare.h @@ -9,13 +9,13 @@ extern "C" { #define Array_declare(type)\ typedef struct Array_##type{\ type* values;\ - uint32 length;\ + u32 length;\ bool allocatedOnHeap;\ } Array_##type;\ \ ktid_declare(Array_##type);\ \ -static inline Array_##type Array_##type##_allocValues(uint32 length){\ +static inline Array_##type Array_##type##_allocValues(u32 length){\ return (Array_##type) {\ .values=(type*)malloc(sizeof(type)*length),\ .length=length,\ @@ -23,7 +23,7 @@ static inline Array_##type Array_##type##_allocValues(uint32 length){\ };\ }\ \ -static inline Array_##type Array_##type##_fromBuffer(type* buffer, uint32 bufferLength, bool allocatedOnHeap){\ +static inline Array_##type Array_##type##_fromBuffer(type* buffer, u32 bufferLength, bool allocatedOnHeap){\ return (Array_##type) {\ .values=buffer,\ .length=bufferLength,\ diff --git a/src/Autoarr/Autoarr.c b/src/Autoarr/Autoarr.c index 274f777..84c8c21 100644 --- a/src/Autoarr/Autoarr.c +++ b/src/Autoarr/Autoarr.c @@ -2,13 +2,13 @@ Autoarr_define(char) Autoarr_define(bool) -Autoarr_define(float32) -Autoarr_define(float64) -Autoarr_define(uint8) -Autoarr_define(int8) -Autoarr_define(uint16) -Autoarr_define(int16) -Autoarr_define(uint32) -Autoarr_define(int32) -Autoarr_define(uint64) -Autoarr_define(int64) +Autoarr_define(f32) +Autoarr_define(f64) +Autoarr_define(u8) +Autoarr_define(i8) +Autoarr_define(u16) +Autoarr_define(i16) +Autoarr_define(u32) +Autoarr_define(i32) +Autoarr_define(u64) +Autoarr_define(i64) diff --git a/src/Autoarr/Autoarr.h b/src/Autoarr/Autoarr.h index e22059a..23e6f11 100644 --- a/src/Autoarr/Autoarr.h +++ b/src/Autoarr/Autoarr.h @@ -10,16 +10,16 @@ extern "C" { Autoarr_declare(char) Autoarr_declare(bool) -Autoarr_declare(float32) -Autoarr_declare(float64) -Autoarr_declare(int8) -Autoarr_declare(uint8) -Autoarr_declare(int16) -Autoarr_declare(uint16) -Autoarr_declare(int32) -Autoarr_declare(uint32) -Autoarr_declare(int64) -Autoarr_declare(uint64) +Autoarr_declare(f32) +Autoarr_declare(f64) +Autoarr_declare(i8) +Autoarr_declare(u8) +Autoarr_declare(i16) +Autoarr_declare(u16) +Autoarr_declare(i32) +Autoarr_declare(u32) +Autoarr_declare(i64) +Autoarr_declare(u64) #if __cplusplus diff --git a/src/Autoarr/Autoarr_KVPair_exported.c b/src/Autoarr/Autoarr_KVPair_exported.c index 8bfbd56..77a6f69 100644 --- a/src/Autoarr/Autoarr_KVPair_exported.c +++ b/src/Autoarr/Autoarr_KVPair_exported.c @@ -5,7 +5,7 @@ extern "C" { #include "Autoarr.h" #include "../Hashtable/KeyValuePair.h" -EXPORT void CALL kerep_Autoarr_KVPair_create(uint16 max_blocks_count, uint16 max_block_length, Autoarr_KVPair** output){ +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); } @@ -13,7 +13,7 @@ EXPORT void CALL kerep_Autoarr_KVPair_free(Autoarr_KVPair* ar){ Autoarr_free(ar, true); } -EXPORT void CALL kerep_Autoarr_KVPair_get(Autoarr_KVPair* ar, uint32 index, KVPair* output){ +EXPORT void CALL kerep_Autoarr_KVPair_get(Autoarr_KVPair* ar, u32 index, KVPair* output){ *output=Autoarr_get(ar, index); } @@ -21,15 +21,15 @@ EXPORT void CALL kerep_Autoarr_KVPair_add(Autoarr_KVPair* ar, KVPair element){ Autoarr_add(ar, element); } -EXPORT void CALL kerep_Autoarr_KVPair_set(Autoarr_KVPair* ar, uint32 index, KVPair element){ +EXPORT void CALL kerep_Autoarr_KVPair_set(Autoarr_KVPair* ar, u32 index, KVPair element){ Autoarr_set(ar, index, element); } -EXPORT void CALL kerep_Autoarr_KVPair_length(Autoarr_KVPair* ar, uint32* output){ +EXPORT void CALL kerep_Autoarr_KVPair_length(Autoarr_KVPair* ar, u32* output){ *output=Autoarr_length(ar); } -EXPORT void CALL kerep_Autoarr_KVPair_max_length(Autoarr_KVPair* ar, uint32* output){ +EXPORT void CALL kerep_Autoarr_KVPair_max_length(Autoarr_KVPair* ar, u32* output){ *output=Autoarr_max_length(ar); } diff --git a/src/Autoarr/Autoarr_Unitype.h b/src/Autoarr/Autoarr_Unitype.h index cf49c7c..fdcd4e5 100644 --- a/src/Autoarr/Autoarr_Unitype.h +++ b/src/Autoarr/Autoarr_Unitype.h @@ -16,12 +16,12 @@ void ____Autoarr_free_Unitype_(void* ar); #define Autoarr_foreach(ar,elem,codeblock)({\ if(ar->blocks_count>0) {\ typeof(**ar->values) elem;\ - for(uint32 blockI=0;blockIblocks_count-1;blockI++)\ - for(uint32 elemI=0;elemImax_block_length;elemI++){\ + for(u32 blockI=0;blockIblocks_count-1;blockI++)\ + for(u32 elemI=0;elemImax_block_length;elemI++){\ elem=ar->values[blockI][elemI];\ (codeblock);\ }\ - for(uint32 elemI=0;elemIblock_length;elemI++){\ + for(u32 elemI=0;elemIblock_length;elemI++){\ elem=ar->values[ar->blocks_count-1][elemI];\ (codeblock);\ }\ diff --git a/src/Autoarr/Autoarr_Unitype_exported.c b/src/Autoarr/Autoarr_Unitype_exported.c index 2aded2e..6db8a6d 100644 --- a/src/Autoarr/Autoarr_Unitype_exported.c +++ b/src/Autoarr/Autoarr_Unitype_exported.c @@ -4,7 +4,7 @@ extern "C" { #include "Autoarr.h" -EXPORT void CALL kerep_Autoarr_Unitype_create(uint16 max_blocks_count, uint16 max_block_length, Autoarr_Unitype** output){ +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); } @@ -12,7 +12,7 @@ EXPORT void CALL kerep_Autoarr_Unitype_free(Autoarr_Unitype* ar){ Autoarr_free(ar, true); } -EXPORT void CALL kerep_Autoarr_Unitype_get(Autoarr_Unitype* ar, uint32 index, Unitype* output){ +EXPORT void CALL kerep_Autoarr_Unitype_get(Autoarr_Unitype* ar, u32 index, Unitype* output){ *output=Autoarr_get(ar, index); } @@ -20,15 +20,15 @@ EXPORT void CALL kerep_Autoarr_Unitype_add(Autoarr_Unitype* ar, Unitype element) Autoarr_add(ar, element); } -EXPORT void CALL kerep_Autoarr_Unitype_set(Autoarr_Unitype* ar, uint32 index, Unitype element){ +EXPORT void CALL kerep_Autoarr_Unitype_set(Autoarr_Unitype* ar, u32 index, Unitype element){ Autoarr_set(ar, index, element); } -EXPORT void CALL kerep_Autoarr_Unitype_length(Autoarr_Unitype* ar, uint32* output){ +EXPORT void CALL kerep_Autoarr_Unitype_length(Autoarr_Unitype* ar, u32* output){ *output=Autoarr_length(ar); } -EXPORT void CALL kerep_Autoarr_Unitype_max_length(Autoarr_Unitype* ar, uint32* output){ +EXPORT void CALL kerep_Autoarr_Unitype_max_length(Autoarr_Unitype* ar, u32* output){ *output=Autoarr_max_length(ar); } diff --git a/src/Autoarr/Autoarr_declare.h b/src/Autoarr/Autoarr_declare.h index dc16829..d449b5b 100644 --- a/src/Autoarr/Autoarr_declare.h +++ b/src/Autoarr/Autoarr_declare.h @@ -12,25 +12,25 @@ struct Autoarr_##type;\ \ typedef struct {\ void (*add)(struct Autoarr_##type* ar, type element);\ - type (*get)(struct Autoarr_##type* ar, uint32 index);\ - type* (*getptr)(struct Autoarr_##type* ar, uint32 index);\ - void (*set)(struct Autoarr_##type* ar, uint32 index, type element);\ + type (*get)(struct Autoarr_##type* ar, u32 index);\ + type* (*getptr)(struct Autoarr_##type* ar, u32 index);\ + void (*set)(struct Autoarr_##type* ar, u32 index, type element);\ void (*freear)(struct Autoarr_##type* ar, bool freePtr);\ type* (*toArray)(struct Autoarr_##type* ar);\ } __functions_list_t_##type;\ \ typedef struct Autoarr_##type{\ - uint16 blocks_count;\ - uint16 max_blocks_count;\ - uint16 block_length;\ - uint16 max_block_length;\ + u16 blocks_count;\ + u16 max_blocks_count;\ + u16 block_length;\ + u16 max_block_length;\ type** values;\ __functions_list_t_##type* functions;\ } Autoarr_##type;\ \ ktid_declare(Autoarr_##type);\ \ -Autoarr_##type* __Autoarr_create_##type(uint16 max_blocks_count, uint16 max_block_length);\ +Autoarr_##type* __Autoarr_create_##type(u16 max_blocks_count, u16 max_block_length);\ void __Autoarr_free_##type(Autoarr_##type* ar, bool freePtr);\ void ____Autoarr_free_##type(void* ar); @@ -52,10 +52,10 @@ void ____Autoarr_free_##type(void* ar); autoarr->functions->toArray(autoarr) #define Autoarr_length(autoarr) \ - (uint32)(!autoarr->blocks_count ? 0 : \ + (u32)(!autoarr->blocks_count ? 0 : \ autoarr->max_block_length*(autoarr->blocks_count-1)+autoarr->block_length) #define Autoarr_max_length(autoarr)\ - (uint32)(autoarr->max_block_length*autoarr->max_blocks_count) + (u32)(autoarr->max_block_length*autoarr->max_blocks_count) #define Autoarr_pop(AR){\ if(AR->block_length==1){\ diff --git a/src/Autoarr/Autoarr_define.h b/src/Autoarr/Autoarr_define.h index 32b665a..9e82e4d 100644 --- a/src/Autoarr/Autoarr_define.h +++ b/src/Autoarr/Autoarr_define.h @@ -26,23 +26,23 @@ create_block:\ ar->block_length++;\ }\ \ -type __Autoarr_get_##type(Autoarr_##type* ar, uint32 index){\ +type __Autoarr_get_##type(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];\ }\ \ -type* __Autoarr_getptr_##type(Autoarr_##type* ar, uint32 index){\ +type* __Autoarr_getptr_##type(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);\ }\ \ -void __Autoarr_set_##type(Autoarr_##type* ar, uint32 index, type element){\ +void __Autoarr_set_##type(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;\ }\ \ void __Autoarr_free_##type(Autoarr_##type* ar, bool freePtr){\ - for(uint16 i=0; iblocks_count;i++)\ + for(u16 i=0; iblocks_count;i++)\ free(ar->values[i]); \ free(ar->values);\ if(freePtr) free(ar);\ @@ -52,9 +52,9 @@ void ____Autoarr_free_##type(void* ar){\ }\ \ type* __Autoarr_toArray_##type(Autoarr_##type* ar){\ - uint32 length=Autoarr_length(ar);\ + u32 length=Autoarr_length(ar);\ type* array=malloc(length * sizeof(type));\ - for(uint32 i=0; irows[h]; } diff --git a/src/DtsodParser/DtsodV24_serialize.c b/src/DtsodParser/DtsodV24_serialize.c index f68e706..0ec6444 100644 --- a/src/DtsodParser/DtsodV24_serialize.c +++ b/src/DtsodParser/DtsodV24_serialize.c @@ -4,18 +4,18 @@ typedef struct SerializeSharedData{ StringBuilder* sh_builder; - uint8 sh_tabs; + u8 sh_tabs; } SerializeSharedData; #define b shared->sh_builder #define tabs shared->sh_tabs -Maybe __serialize(StringBuilder* _b, uint8 _tabs, Hashtable* dtsod); +Maybe __serialize(StringBuilder* _b, u8 _tabs, Hashtable* dtsod); #define addc(C) StringBuilder_append_char(b,C) void __AppendTabs(SerializeSharedData* shared) { - for (uint8 t = 0; t < tabs; t++) + for (u8 t = 0; t < tabs; t++) addc( '\t'); }; #define AppendTabs() __AppendTabs(shared) @@ -23,15 +23,15 @@ void __AppendTabs(SerializeSharedData* shared) { Maybe __AppendValue(SerializeSharedData* shared, Unitype u); #define AppendValue(UNI) __AppendValue(shared, UNI) Maybe __AppendValue(SerializeSharedData* shared, Unitype u){ - if(u.typeId==ktid_name(int64)){ - StringBuilder_append_int64(b,u.Int64); + if(u.typeId==ktid_name(i64)){ + StringBuilder_append_i64(b,u.Int64); } - else if(u.typeId==ktid_name(uint64)){ - StringBuilder_append_uint64(b,u.UInt64); + else if(u.typeId==ktid_name(u64)){ + StringBuilder_append_u64(b,u.UInt64); addc('u'); } - else if(u.typeId==ktid_name(float64)){ - StringBuilder_append_float64(b,u.Float64); + else if(u.typeId==ktid_name(f64)){ + StringBuilder_append_f64(b,u.Float64); addc('f'); } else if(u.typeId==ktid_ptrName(char)){ @@ -102,7 +102,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){ return MaybeNull; }; -Maybe __serialize(StringBuilder* _b, uint8 _tabs, Hashtable* dtsod){ +Maybe __serialize(StringBuilder* _b, u8 _tabs, Hashtable* dtsod){ SerializeSharedData _shared={ .sh_builder=_b, .sh_tabs=_tabs diff --git a/src/Filesystem/dir.c b/src/Filesystem/dir.c index 78f9cb0..c98e732 100644 --- a/src/Filesystem/dir.c +++ b/src/Filesystem/dir.c @@ -16,7 +16,7 @@ bool dir_exists(const char* path){ (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is a directory #else struct stat stats; - int rez=stat(path, &stats); + i32 rez=stat(path, &stats); return (bool)( (rez!=-1) & // file exists (S_ISDIR(stats.st_mode))); // file is a directory diff --git a/src/Filesystem/file.c b/src/Filesystem/file.c index cbedced..7e7c496 100644 --- a/src/Filesystem/file.c +++ b/src/Filesystem/file.c @@ -19,7 +19,7 @@ bool file_exists(const char* path){ !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is not directory #else struct stat stats; - int rez=stat(path, &stats); + i32 rez=stat(path, &stats); return (bool)( (rez!=-1) & // file exists !(S_ISDIR(stats.st_mode))); // file is not directory @@ -68,36 +68,36 @@ Maybe file_close(File* file){ safethrow(ERR_IO,;); Maybe file_writeChar(File* file, char byte){ - int rezult=fputc(byte, file); + i32 rezult=fputc(byte, file); ioWriteCheck(); return MaybeNull; } -Maybe file_writeBuffer(File* file, char* buffer, uint64 length){ - int rezult=0; - for(uint64 i=0; i -Maybe file_writeBuffer(File* file, char* buffer, uint64 length); +Maybe file_writeBuffer(File* file, char* buffer, u64 length); /// @brief writes all cstring array content to file /// @param cptr zero-terminated cstring @@ -63,12 +63,12 @@ Maybe file_readChar(File* file); /// @brief reads byte array of specofied length /// @param buffer buffer that will be filled with file bytes /// @param length buffer length -/// @return Maybe total number of successfully read bytes (<=length) -Maybe file_readBuffer(File* file, char* buffer, uint64 length); +/// @return Maybe total number of successfully read bytes (<=length) +Maybe file_readBuffer(File* file, char* buffer, u64 length); /// @brief reads all bytes from file /// @param allBytes ptr to the file's content will be pushed there -/// @return Maybe total number of successfully read bytes +/// @return Maybe total number of successfully read bytes Maybe file_readAll(File* file, char** allBytes); #if __cplusplus diff --git a/src/Filesystem/path.c b/src/Filesystem/path.c index 5cd2d6e..b3d046e 100644 --- a/src/Filesystem/path.c +++ b/src/Filesystem/path.c @@ -1,16 +1,16 @@ #include "filesystem.h" -char* __path_concat(uint16 n, ...){ +char* __path_concat(u16 n, ...){ char** parts=(char**)malloc(n*sizeof(char*)); - uint32* lengths=malloc(n*sizeof(uint32)); - uint32 totalLength=0; + u32* lengths=malloc(n*sizeof(u32)); + u32 totalLength=0; // reading args from va_list va_list vl; va_start(vl, n); - for(uint16 i=0; i between them /// @return new cstr #define path_concat(PATH_PARTS...) __path_concat(count_args(PATH_PARTS), PATH_PARTS) diff --git a/src/HashFunctions/hash.c b/src/HashFunctions/hash.c index 9035ef0..3f2761b 100644 --- a/src/HashFunctions/hash.c +++ b/src/HashFunctions/hash.c @@ -1,14 +1,14 @@ #include "hash.h" -uint32 hash_sdbm32(uint32 oldhash, void* buf, uint32 len){ - uint8* ubuf=(uint8*)buf; - register uint32 hash=oldhash; +u32 hash_sdbm32(u32 oldhash, void* buf, u32 len){ + u8* ubuf=(u8*)buf; + register u32 hash=oldhash; for (; len ; len--, ubuf++) hash=(hash<<6)+(hash<<16)-hash+*ubuf; return hash; } -static const uint32 crc_32_tab[]={ +static const u32 crc_32_tab[]={ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, @@ -75,19 +75,19 @@ static const uint32 crc_32_tab[]={ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -uint32 hash_crc32(uint32 oldhash, void* buf, uint32 len){ - uint8* ubuf=(uint8*)buf; - register uint32 crc=oldhash; +u32 hash_crc32(u32 oldhash, void* buf, u32 len){ + u8* ubuf=(u8*)buf; + register u32 crc=oldhash; for (; len; --len, ++ubuf) crc=crc_32_tab[(crc^(*ubuf)) & 0xff] ^ (crc>>8); return ~crc; } -// bool hashf_crc32c(char *name, uint32 *crc, long *charcnt) { +// bool hashf_crc32c(char *name, u32 *crc, long *charcnt) { // register FILE *fin; -// register uint32 oldcrc32; -// register int c; +// register u32 oldcrc32; +// register i32 c; // oldcrc32 = 0xFFFFFFFF; *charcnt = 0; // if ((fin=fopen(name, "r"))==NULL) { diff --git a/src/HashFunctions/hash.h b/src/HashFunctions/hash.h index 753ed11..c4b71ef 100644 --- a/src/HashFunctions/hash.h +++ b/src/HashFunctions/hash.h @@ -9,8 +9,8 @@ extern "C" { #define hashb(FUNC, BUF, LEN) FUNC(0xFFFFFFFF, BUF, LEN) #define hashs(FUNC, STR) FUNC(0xFFFFFFFF, STR, cptr_length(STR)) -uint32 hash_sdbm32(uint32 oldhash, void* buf, uint32 len); -uint32 hash_crc32(uint32 oldhash, void* buf, uint32 len); +u32 hash_sdbm32(u32 oldhash, void* buf, u32 len); +u32 hash_crc32(u32 oldhash, void* buf, u32 len); #if __cplusplus } diff --git a/src/Hashtable/Hashtable.c b/src/Hashtable/Hashtable.c index edab896..82e92ca 100644 --- a/src/Hashtable/Hashtable.c +++ b/src/Hashtable/Hashtable.c @@ -3,7 +3,7 @@ ktid_define(Hashtable); // amount of rows -static const uint16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521}; +static const u16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521}; #define HT_HEIN_MIN 0 #define HT_HEIN_MAX 6 @@ -14,14 +14,14 @@ Hashtable* Hashtable_create(){ Hashtable* ht=malloc(sizeof(Hashtable)); ht->hein=HT_HEIN_MIN; ht->rows=malloc(HT_HEIGHTS[HT_HEIN_MIN]*sizeof(Autoarr(KVPair)*)); - for(uint16 i=0;irows[i]=Autoarr_create(KVPair,ARR_BC,ARR_BL); return ht; } void __Hashtable_free(void* _ht){ Hashtable* ht=_ht; - for(uint16 i=0;ihein];i++) + for(u16 i=0;ihein];i++) Autoarr_free(ht->rows[i], true); free(ht->rows); } @@ -30,22 +30,22 @@ void Hashtable_free(Hashtable* ht){ free(ht); } -uint16 Hashtable_height(Hashtable* ht) { return HT_HEIGHTS[ht->hein]; } +u16 Hashtable_height(Hashtable* ht) { return HT_HEIGHTS[ht->hein]; } void Hashtable_expand(Hashtable* ht){ if(ht->hein>=HT_HEIN_MAX) throw(ERR_MAXLENGTH); Autoarr(KVPair)** newrows=malloc(HT_HEIGHTS[++ht->hein]*sizeof(Autoarr(KVPair)*)); - for(uint16 i=0;ihein];i++) + for(u16 i=0;ihein];i++) newrows[i]=Autoarr_create(KVPair,ARR_BC,ARR_BL); - for(uint16 i=0;ihein-1];i++){ + for(u16 i=0;ihein-1];i++){ Autoarr(KVPair)* ar=ht->rows[i]; - uint32 arlen=Autoarr_length(ar); - for(uint32 k=0;khein]; + u16 newrown=hashs(hash_sdbm32, p.key)%HT_HEIGHTS[ht->hein]; Autoarr(KVPair)* newar=newrows[newrown]; Autoarr_add(newar,p); } @@ -58,7 +58,7 @@ void Hashtable_expand(Hashtable* ht){ } Autoarr(KVPair)* getrow(Hashtable* ht, char* key, bool can_expand){ - uint32 hash=hashs(hash_sdbm32, key); + u32 hash=hashs(hash_sdbm32, key); Autoarr(KVPair)* ar=ht->rows[hash%HT_HEIGHTS[ht->hein]]; if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar)) Hashtable_expand(ht); @@ -74,8 +74,8 @@ void Hashtable_add(Hashtable* ht, char* key, Unitype u){ // returns null or pointer to value in hashtable Unitype* Hashtable_getptr(Hashtable* ht, char* key){ Autoarr(KVPair)* ar=getrow(ht,key,false); - uint32 arlen=Autoarr_length(ar); - for(uint32 i=0;ikey)) return &p->value; } @@ -84,8 +84,8 @@ Unitype* Hashtable_getptr(Hashtable* ht, char* key){ Unitype Hashtable_get(Hashtable* ht, char* key){ Autoarr(KVPair)* ar=getrow(ht,key,false); - uint32 arlen=Autoarr_length(ar); - for(uint32 i=0;irows[h];\ Autoarr_foreach(AR, EL, codeblock);\ }\ diff --git a/src/SearchTree/SearchTree.c b/src/SearchTree/SearchTree.c index 2a0617f..81b7083 100644 --- a/src/SearchTree/SearchTree.c +++ b/src/SearchTree/SearchTree.c @@ -14,13 +14,13 @@ void __STNode_free(void* _node){ STNode* node=_node; if (!node) throw(ERR_NULLPTR); if(node->branches){ - for(uint8 n32 = 0;n32<8;n32++){ + for(u8 n32 = 0;n32<8;n32++){ STNode*** ptrn32=(STNode***)node->branches[n32]; if(ptrn32){ - for(uint8 n4 = 0;n4<8;n4++){ + for(u8 n4 = 0;n4<8;n4++){ STNode** ptrn4=ptrn32[n4]; if (ptrn4){ - for(uint8 rem=0;rem<4;rem++){ + for(u8 rem=0;rem<4;rem++){ STNode* ptrrem=ptrn4[rem]; if(ptrrem) STNode_free(ptrrem); @@ -41,9 +41,9 @@ void STNode_free(STNode* node){ free(node); } -typedef struct {uint8 n32, n4, rem;} indexes3; +typedef struct {u8 n32, n4, rem;} indexes3; -indexes3 splitindex(uint8 i){ +indexes3 splitindex(u8 i){ return (indexes3){ .n32=i/32, .n4=i%32/4, @@ -60,20 +60,20 @@ void ST_pushString(STNode* node_first, string key, Unitype value){ if (!node_first) throw(ERR_NULLPTR); STNode* node_last=node_first; while(key.length--){ - indexes3 i3=splitindex((uint8)*key.ptr); + indexes3 i3=splitindex((u8)*key.ptr); if(!node_last->branches){ node_last->branches=(STNode****)malloc(8*sizeof(STNode***)); - for(uint8 i=0;i<8;i++) + for(u8 i=0;i<8;i++) node_last->branches[i]=(STNode***)NULL; } if(!node_last->branches[i3.n32]){ node_last->branches[i3.n32]=(STNode***)malloc(8*sizeof(STNode**)); - for(uint8 i=0;i<8;i++) + for(u8 i=0;i<8;i++) node_last->branches[i3.n32][i]=(STNode**)NULL; } if(!node_last->branches[i3.n32][i3.n4]){ node_last->branches[i3.n32][i3.n4]=(STNode**)malloc(4*sizeof(STNode*)); - for(uint8 i=0;i<4;i++) + for(u8 i=0;i<4;i++) node_last->branches[i3.n32][i3.n4][i]=(STNode*)NULL; } if(!node_last->branches[i3.n32][i3.n4][i3.rem]) @@ -93,7 +93,7 @@ Unitype ST_pullString(STNode* node_first, string key){ if (!node_first) throw(ERR_NULLPTR); STNode* node_last=node_first; while (key.length--){ - indexes3 i3=splitindex((uint8)*key.ptr); + indexes3 i3=splitindex((u8)*key.ptr); if(!node_last->branches) return UniNull; STNode*** ptrn32=(STNode***)node_last->branches[i3.n32]; if(!ptrn32) return UniNull; diff --git a/src/String/StringBuilder.c b/src/String/StringBuilder.c index e3c3244..3ee6aa8 100644 --- a/src/String/StringBuilder.c +++ b/src/String/StringBuilder.c @@ -11,16 +11,16 @@ ktid_define(StringBuilder); void complete_buf(StringBuilder* b){ if(!b->compl_bufs) b->compl_bufs=Autoarr_create(string,BL_C,BL_L); - uint32 len=Autoarr_length(b->curr_buf); + u32 len=Autoarr_length(b->curr_buf); if(!len) return; string str={.length=len, .ptr=malloc(len)}; - uint32 i=0; + u32 i=0; Autoarr_foreach(b->curr_buf, c, ({ str.ptr[i++]=c; })); Autoarr_add(b->compl_bufs,str); Autoarr_free(b->curr_buf, true); - b->curr_buf=Autoarr_create(int8,BL_C,BL_L); + b->curr_buf=Autoarr_create(i8,BL_C,BL_L); } void try_complete_buf(StringBuilder* b){ @@ -32,7 +32,7 @@ void try_complete_buf(StringBuilder* b){ StringBuilder* StringBuilder_create(){ StringBuilder* b=malloc(sizeof(StringBuilder)); b->compl_bufs=NULL; - b->curr_buf=Autoarr_create(int8,BL_C,BL_L); + b->curr_buf=Autoarr_create(i8,BL_C,BL_L); return b; } @@ -48,15 +48,15 @@ void StringBuilder_free(StringBuilder* b){ string StringBuilder_build(StringBuilder* b){ complete_buf(b); - uint32 len=0; + u32 len=0; Autoarr_foreach(b->compl_bufs, cs, ({ len+=cs.length; })); string str= { .length=len, .ptr=malloc(len+1) }; str.ptr[len]='\0'; - uint32 i=0; + u32 i=0; Autoarr_foreach(b->compl_bufs, cs, ({ - for(uint32 n=0;ncurr_buf,s.ptr[i]); } -void StringBuilder_append_int64(StringBuilder* b, int64 a){ +void StringBuilder_append_i64(StringBuilder* b, i64 a){ try_complete_buf(b); - uint8 i=0; + u8 i=0; if(a==0){ Autoarr_add(b->curr_buf,'0'); return; @@ -121,9 +121,9 @@ void StringBuilder_append_int64(StringBuilder* b, int64 a){ free(rev.ptr); } -void StringBuilder_append_uint64(StringBuilder* b, uint64 a){ +void StringBuilder_append_u64(StringBuilder* b, u64 a){ try_complete_buf(b); - uint8 i=0; + u8 i=0; if(a==0){ Autoarr_add(b->curr_buf,'0'); return; @@ -138,7 +138,7 @@ void StringBuilder_append_uint64(StringBuilder* b, uint64 a){ free(rev.ptr); } -void StringBuilder_append_float64(StringBuilder* b, double a){ +void StringBuilder_append_f64(StringBuilder* b, f64 a){ try_complete_buf(b); char buf[32]; IFMSC( diff --git a/src/String/StringBuilder.h b/src/String/StringBuilder.h index 8072cab..227df3f 100644 --- a/src/String/StringBuilder.h +++ b/src/String/StringBuilder.h @@ -11,7 +11,7 @@ Autoarr_declare(string) typedef struct StringBuilder{ Autoarr(string)* compl_bufs; - Autoarr(int8)* curr_buf; + Autoarr(i8)* curr_buf; } StringBuilder; ktid_declare(StringBuilder); @@ -28,9 +28,9 @@ void StringBuilder_rmchar(StringBuilder* b); void StringBuilder_append_char(StringBuilder* b, char c); void StringBuilder_append_cptr(StringBuilder* b, char* s); void StringBuilder_append_string(StringBuilder* b, string s); -void StringBuilder_append_int64(StringBuilder* b, int64 a); -void StringBuilder_append_uint64(StringBuilder* b, uint64 a); -void StringBuilder_append_float64(StringBuilder* b, double a); +void StringBuilder_append_i64(StringBuilder* b, i64 a); +void StringBuilder_append_u64(StringBuilder* b, u64 a); +void StringBuilder_append_f64(StringBuilder* b, f64 a); #if __cplusplus } diff --git a/src/String/string.c b/src/String/string.c index 9864fb1..5d2246a 100644 --- a/src/String/string.c +++ b/src/String/string.c @@ -19,7 +19,7 @@ string string_copy(string src){ string nstr; nstr.length=src.length; nstr.ptr=malloc(nstr.length); - for(uint32 i=0;i=0; si--){ + i32 fi_last=cptr_length(fragment)-1; + for(i32 si=cptr_length(ptr)-1, fi=fi_last; si>=0; si--){ sc=ptr[si]; if(sc==fragment[fi]){ if(fi==0) @@ -85,9 +85,9 @@ uint32 cptr_lastIndexOf(char* ptr, char* fragment){ } return -1; } -uint32 cptr_lastIndexOfChar(char* ptr, char fragment){ +u32 cptr_lastIndexOfChar(char* ptr, char fragment){ char sc=*ptr; - for(int si=cptr_length(ptr)-1; si>=0; si--){ + for(i32 si=cptr_length(ptr)-1; si>=0; si--){ sc=ptr[si]; if(sc==fragment){ return si; @@ -96,24 +96,24 @@ uint32 cptr_lastIndexOfChar(char* ptr, char fragment){ return -1; } -void memcopy(void* from, void* to, uint32 size){ +void memcopy(void* from, void* to, u32 size){ if(from==NULL || to==NULL) throw(ERR_NULLPTR); - for(uint32 i=0; i in /// @return index of first inclusion or -1 if not found -uint32 cptr_indexOf(char* ptr, char* fragment); +u32 cptr_indexOf(char* ptr, char* fragment); /// @brief search for in /// @return index of first inclusion or -1 if not found -uint32 cptr_indexOfChar(char* ptr, char fragment); +u32 cptr_indexOfChar(char* ptr, char fragment); /// @brief search for in /// @return index of last inclusion or -1 if not found -uint32 cptr_lastIndexOf(char* ptr, char* fragment); +u32 cptr_lastIndexOf(char* ptr, char* fragment); /// @brief search for in /// @return index of last inclusion or -1 if not found -uint32 cptr_lastIndexOfChar(char* ptr, char fragment); +u32 cptr_lastIndexOfChar(char* ptr, char fragment); static inline bool cptr_contains(char* ptr, char* fragment){ // if(cptr_indexOf(ptr, fragment)==-1) @@ -42,9 +42,9 @@ static inline bool cptr_contains(char* ptr, char* fragment){ return cptr_indexOf(ptr, fragment) +1; } -void memcopy(void* from, void* to, uint32 size); +void memcopy(void* from, void* to, u32 size); -char* __cptr_concat(uint16 n, ...); +char* __cptr_concat(u16 n, ...); #define cptr_concat(STR...) __cptr_concat(count_args(STR), STR) #if __cplusplus diff --git a/src/base/endian.c b/src/base/endian.c index b6e25f6..282a53b 100644 --- a/src/base/endian.c +++ b/src/base/endian.c @@ -2,7 +2,7 @@ static const union { - uint16 number; + u16 number; Endian bytes[2]; } _endian_union={ .number=0x0102 }; diff --git a/src/base/errors.c b/src/base/errors.c index dacf45b..a93aff6 100644 --- a/src/base/errors.c +++ b/src/base/errors.c @@ -23,7 +23,7 @@ char* errname(ErrorId err){ #define ERRMSG_MAXLENGTH 1024 -char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){ +char* __genErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname){ size_t bufsize=ERRMSG_MAXLENGTH; char* rezult=malloc(bufsize); IFMSC( @@ -33,7 +33,7 @@ char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* return rezult; } -char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){ +char* __extendErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname){ size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH; char* rezult=malloc(bufsize); IFMSC( diff --git a/src/base/errors.h b/src/base/errors.h index 90d9751..bb1dce6 100644 --- a/src/base/errors.h +++ b/src/base/errors.h @@ -17,8 +17,8 @@ PACK_ENUM(ErrorId, char* errname(ErrorId err); -char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname); -char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname); +char* __genErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname); +char* __extendErrMsg(const char* errmsg, const char* srcfile, i32 line, const char* funcname); typedef struct Maybe{ Unitype value; diff --git a/src/base/optime.h b/src/base/optime.h index be45fe4..8f5bd2d 100644 --- a/src/base/optime.h +++ b/src/base/optime.h @@ -4,7 +4,7 @@ #define __optime_print(opname, t)\ char tnames[3][3]={"s\0","ms","us"};\ - int tni=0;\ + i32 tni=0;\ if(t>1000000){\ t/=1000000;\ tni=0;\ @@ -17,25 +17,25 @@ #ifdef CLOCK_REALTIME /// executes codeblock and prints execution time -/// uint64 op_i is counter of the internal loop +/// u64 op_i is counter of the internal loop /// uses non-standard high-precision clock #define optime(opname,repeats,codeblock) ({\ struct timespec start, stop;\ clock_gettime(CLOCK_REALTIME, &start);\ - for(uint64 op_i=0;op_i<(uint64)repeats;op_i++)\ + for(u64 op_i=0;op_i<(u64)repeats;op_i++)\ (codeblock);\ clock_gettime(CLOCK_REALTIME, &stop);\ - double t=(double)(stop.tv_sec-start.tv_sec)*1000000+(double)(stop.tv_nsec-start.tv_nsec)/1000;\ + f64 t=(f64)(stop.tv_sec-start.tv_sec)*1000000+(f64)(stop.tv_nsec-start.tv_nsec)/1000;\ __optime_print(opname,t)\ }) #else /// uses standard low precision clock #define optime(opname,repeats,codeblock) ({\ clock_t start=clock();\ - for(uint64 op_i=0;op_i<(uint64)repeats;op_i++)\ + for(u64 op_i=0;op_i<(u64)repeats;op_i++)\ (codeblock);\ clock_t stop=clock();\ - double t=(double)(stop-start)/CLOCKS_PER_SEC*1000000;\ + f64 t=(f64)(stop-start)/CLOCKS_PER_SEC*1000000;\ __optime_print(opname,t)\ }) #endif diff --git a/src/base/std.h b/src/base/std.h index 9f6b7d9..d102a70 100644 --- a/src/base/std.h +++ b/src/base/std.h @@ -12,22 +12,23 @@ extern "C" { #include #include -typedef int8_t int8; -typedef uint8_t uint8; -typedef int16_t int16; -typedef uint16_t uint16; -typedef int32_t int32; -typedef uint32_t uint32; -typedef int64_t int64; -typedef uint64_t uint64; -typedef float float32; -typedef double float64; +typedef int8_t i8; +typedef uint8_t u8; +typedef int16_t i16; +typedef uint16_t u16; +typedef int32_t i32; +typedef uint32_t u32; +typedef int64_t i64; +typedef uint64_t u64; +typedef float f32; +typedef double f64; + // Usually bool from stdbool.h is defined as macro, // so in other macros like ktid_##TYPE it will be replaced by _Bool. // ktid__Bool will be created instead of ktid_bool // In C++ bool is a keyword, so there is no need to redefine it. #if !__cplusplus -typedef uint8 bool; +typedef u8 bool; #define true 1 #define false 0 #endif diff --git a/src/base/type_system/base_toString.c b/src/base/type_system/base_toString.c index 68c5324..42deca9 100644 --- a/src/base/type_system/base_toString.c +++ b/src/base/type_system/base_toString.c @@ -2,7 +2,7 @@ #include "../base.h" #include "../../kprint/kprint_format.h" -char* __toString_char(void* c, uint32 fmt) { +char* __toString_char(void* c, u32 fmt) { //*c=char if(kp_fmt_dataFormat(fmt)==kp_c){ char* cc=malloc(2); @@ -17,9 +17,9 @@ char* __toString_char(void* c, uint32 fmt) { else throw(ERR_FORMAT); } -char* __toString_bool(void* c, uint32 fmt) { +char* __toString_bool(void* c, u32 fmt) { static const char _strbool[4][6]={ "false", "true\0", "False", "True\0" }; - uint8 strind=*(bool*)c==1 + kp_fmt_isUpper(fmt)*2; + u8 strind=*(bool*)c==1 + kp_fmt_isUpper(fmt)*2; char* rez=malloc(6); rez[0]=_strbool[strind][0]; rez[1]=_strbool[strind][1]; @@ -30,10 +30,10 @@ char* __toString_bool(void* c, uint32 fmt) { return rez; } -char* toString_int(int64 n){ - int64 d=n<0 ? -1*n : n; +char* toString_i64(i64 n){ + i64 d=n<0 ? -1*n : n; char str[32]; - uint8 i=sizeof(str); + u8 i=sizeof(str); str[--i]=0; if(d==0) str[--i]='0'; @@ -46,9 +46,9 @@ char* toString_int(int64 n){ return cptr_copy((char*)str+i); } -char* toString_uint(uint64 n, bool withPostfix, bool uppercase){ +char* toString_u64(u64 n, bool withPostfix, bool uppercase){ char str[32]; - uint8 i=sizeof(str); + u8 i=sizeof(str); str[--i]=0; if(withPostfix) str[--i]= uppercase ? 'U' : 'u'; @@ -67,7 +67,7 @@ char* toString_uint(uint64 n, bool withPostfix, bool uppercase){ throw("too big precision");\ if(precision==0)\ precision=toString_float_default_precision;\ - int cn=IFMSC(\ + i32 cn=IFMSC(\ sprintf_s(str, bufsize, "%.*f", precision, n),\ sprintf(str, "%.*f", precision, n)\ );\ @@ -80,37 +80,37 @@ char* toString_uint(uint64 n, bool withPostfix, bool uppercase){ return cptr_copy(str);\ } -char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase) - _toString_float_impl(48, toString_float32_max_precision) +char* toString_f32(f32 n, u8 precision, bool withPostfix, bool uppercase) + _toString_float_impl(48, toString_f32_max_precision) -char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase) - _toString_float_impl(512, toString_float64_max_precision) +char* toString_f64(f64 n, u8 precision, bool withPostfix, bool uppercase) + _toString_float_impl(512, toString_f64_max_precision) #define byte_to_bits(byte) {\ - str[cn++]='0' + (uint8)((byte>>7)&1); /* 8th bit */\ - str[cn++]='0' + (uint8)((byte>>6)&1); /* 7th bit */\ - str[cn++]='0' + (uint8)((byte>>5)&1); /* 6th bit */\ - str[cn++]='0' + (uint8)((byte>>4)&1); /* 5th bit */\ - str[cn++]='0' + (uint8)((byte>>3)&1); /* 4th bit */\ - str[cn++]='0' + (uint8)((byte>>2)&1); /* 3th bit */\ - str[cn++]='0' + (uint8)((byte>>1)&1); /* 2th bit */\ - str[cn++]='0' + (uint8)((byte>>0)&1); /* 1th bit */\ + str[cn++]='0' + (u8)((byte>>7)&1); /* 8th bit */\ + str[cn++]='0' + (u8)((byte>>6)&1); /* 7th bit */\ + str[cn++]='0' + (u8)((byte>>5)&1); /* 6th bit */\ + str[cn++]='0' + (u8)((byte>>4)&1); /* 5th bit */\ + str[cn++]='0' + (u8)((byte>>3)&1); /* 4th bit */\ + str[cn++]='0' + (u8)((byte>>2)&1); /* 3th bit */\ + str[cn++]='0' + (u8)((byte>>1)&1); /* 2th bit */\ + str[cn++]='0' + (u8)((byte>>0)&1); /* 1th bit */\ } -char* toString_bin(void* _bytes, uint32 size, bool inverse, bool withPrefix){ +char* toString_bin(void* _bytes, u32 size, bool inverse, bool withPrefix){ char* bytes=_bytes; char* str=malloc(size*8 + (withPrefix?2:0) +1); - uint32 cn=0; // char number + u32 cn=0; // char number if(withPrefix){ str[cn++]='0'; str[cn++]='b'; } if(inverse){ // byte number - for(int32 bn=size-1; bn>=0; bn--) + for(i32 bn=size-1; bn>=0; bn--) byte_to_bits(bytes[bn]) } else { - for(int32 bn=0; bn=0; bn--){ + for(i32 bn=size-1; bn>=0; bn--){ unsigned char byte=bytes[bn]; str[cn++]=_4bitsHex(byte/16, uppercase); str[cn++]=_4bitsHex(byte%16, uppercase); @@ -152,7 +152,7 @@ char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, boo } // right to left else { - for(int32 bn=0; bntypeId); char* valuestr=type.toString(_u, fmt); @@ -30,11 +30,11 @@ char* sprintuni(Unitype v){ ktDescriptor type=ktDescriptor_get(v.typeId); if(v.typeId==ktid_Null) sprintf_s(buf, BUFSIZE, "{Null}"); - else if(v.typeId==ktid_name(float64)) + else if(v.typeId==ktid_name(f64)) sprintf_s(buf, BUFSIZE, "{%s : %lf}", type.name,v.Float64); - else if(v.typeId==ktid_name(bool) || v.typeId==ktid_name(uint64)) + else if(v.typeId==ktid_name(bool) || v.typeId==ktid_name(u64)) sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%llu", "%lu") "}", type.name,v.UInt64); - else if(v.typeId==ktid_name(int64)) + else if(v.typeId==ktid_name(i64)) sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%lld", "%ld") "}", type.name,v.Int64); else if(v.typeId==ktid_ptrName(char)){ size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2; diff --git a/src/base/type_system/unitype.h b/src/base/type_system/unitype.h index e86eedc..d73859d 100644 --- a/src/base/type_system/unitype.h +++ b/src/base/type_system/unitype.h @@ -8,9 +8,9 @@ extern "C" { typedef struct Unitype{ union { - int64 Int64; - uint64 UInt64; - double Float64; + i64 Int64; + u64 UInt64; + f64 Float64; bool Bool; void* VoidPtr; char Bytes[8]; @@ -24,9 +24,9 @@ ktid_declare(Unitype); #define __UniDef(FIELD, TYPE, VAL) (Unitype){\ .FIELD=VAL, .typeId=ktid_name(TYPE), .allocatedInHeap=false} -#define UniInt64(VAL) __UniDef(Int64, int64, VAL) -#define UniUInt64(VAL) __UniDef(UInt64, uint64, VAL) -#define UniFloat64(VAL) __UniDef(Float64, float64, VAL) +#define UniInt64(VAL) __UniDef(Int64, i64, VAL) +#define UniUInt64(VAL) __UniDef(UInt64, u64, VAL) +#define UniFloat64(VAL) __UniDef(Float64, f64, VAL) #define UniBool(VAL) __UniDef(Bool, bool, VAL) #define UniStackPtr(TYPE, VAL) (Unitype){\ diff --git a/src/kprint/README.md b/src/kprint/README.md index cb78373..98464ef 100644 --- a/src/kprint/README.md +++ b/src/kprint/README.md @@ -2,16 +2,16 @@ It is just my cross-plaform variant of printf. Unlike in standard printf, `%l...` and `%ll...` placeholders dont depend on size of `long int` and `long long int`. And you can change terminal colors by unix codes (`\e[92m`) even on Windows. -| type | placeholder | -|-------------------------|-------------------------| -| int8 / int16 / int32 | %i / %d | -| int64 | %li / %ld / %lld / %lli | -| uint8 / uint16 / uint32 | %u | -| uint64 | %lu / %llu | -| float32 / float64 | %f | -| char | %c | -| char[] | %s | -| void\* | %p / %x | +| type | placeholder | +|----------------|-------------------------| +| i8 / i16 / i32 | %i / %d | +| i64 | %li / %ld / %lld / %lli | +| u8 / u16 / u32 | %u | +| u64 | %lu / %llu | +| f32 / f64 | %f | +| char | %c | +| char[] | %s | +| void\* | %p / %x |
diff --git a/src/kprint/kprint.c b/src/kprint/kprint.c index 2fda00f..809de58 100644 --- a/src/kprint/kprint.c +++ b/src/kprint/kprint.c @@ -9,11 +9,11 @@ ktid __typeFromFormat(kp_fmt f){ case kp_i: case kp_h: case kp_b: - return ktid_name(int64); + return ktid_name(i64); case kp_u: - return ktid_name(uint64); + return ktid_name(u64); case kp_f: - return ktid_name(float64); + return ktid_name(f64); case kp_c: return ktid_char; case kp_s: @@ -34,17 +34,17 @@ Maybe __next_toString(kp_fmt f, __kp_value_union* object){ return SUCCESS(UniHeapPtr(char, typeDesc.toString(object, f))); } -Maybe check_argsN(uint8 n){ +Maybe check_argsN(u8 n){ if(n%2 != 0) safethrow("kprint recieved non-even number of arguments",;); if(n > 32) safethrow("kprint recieved >32 number of arguments",;); return MaybeNull; } -Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){ +Maybe __ksprint(u8 n, kp_fmt* formats, __kp_value_union* objects){ try(check_argsN(n), _,;); n/=2; StringBuilder* strb=StringBuilder_create(); - for(uint8 i=0; i>24; + u8 fg=(f&0x0f000000)>>24; if(fg<8) fg+=30; else fg+=90-8; printf("\e[%um", fg); } if(kp_fmt_bgColorSet(f)){ - uint8 bg=(f&0x00f00000)>>20; + u8 bg=(f&0x00f00000)>>20; if(bg<8) bg+=40; else bg+=100-8; printf("\e[%um", bg); @@ -159,13 +159,13 @@ void kprint_setColor(kp_fmt f){ } #endif -/* Maybe ksprint_ar(uint32 count, kp_fmt format, ktid typeId, void* array){ +/* Maybe ksprint_ar(u32 count, kp_fmt format, ktid typeId, void* array){ ktDescriptor typeDesc=ktDescriptor_get(format.typeId); if(!typeDesc.toString) safethrow("type descriptor doesnt have toString() func",;); StringBuilder* strb=StringBuilder_create(); StringBuilder_append_char(strb, '['); - for (uint16 e=1; e @@ -80,7 +80,7 @@ Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects); ) /*-Wint-conversion warning was produced during value to __kp_value_union conversion*/ -Maybe __kfprint(FILE* fd, uint8 n, kp_fmt* formats, __kp_value_union* objects); +Maybe __kfprint(FILE* fd, u8 n, kp_fmt* formats, __kp_value_union* objects); /// @param FD FILE* /// @param ARGS kp_fmt, value, kp_fmt, value... @@ -89,7 +89,7 @@ Maybe __kfprint(FILE* fd, uint8 n, kp_fmt* formats, __kp_value_union* objects); __kfprint(FD, count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\ ) -void __kprint(uint8 n, kp_fmt* formats, __kp_value_union* objects); +void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects); ///can use non-catchable throw !!! ///@param ARGS kp_fmt, value, kp_fmt, value... diff --git a/src/kprint/kprint_format.h b/src/kprint/kprint_format.h index 9efceae..2c8113d 100644 --- a/src/kprint/kprint_format.h +++ b/src/kprint/kprint_format.h @@ -8,7 +8,7 @@ extern "C" { #include "../base/type_system/ktid.h" /// kprint_format -typedef uint32 kp_fmt; +typedef u32 kp_fmt; PACK_ENUM(kp_dataFmt, // 00000000 00000000 00000000 00000000 diff --git a/src/kprint/kprint_format.md b/src/kprint/kprint_format.md index f0b2f7d..e4d811b 100644 --- a/src/kprint/kprint_format.md +++ b/src/kprint/kprint_format.md @@ -54,15 +54,17 @@ bgColorSet─┘││ │ bgColor └data format ## Data format -| format | possible flags | data types | hex value | bin value | -|-----------|----------------|------------|-----------|-----------| -| kp_i | | int8... int64 | 0x00000000 | 00000000 00000000... | -| kp_u | Postfix, Upper | uint8... uint64 | 0x00010000 | 00000000 00000001... | -| kp_h | Prefix, Upper | any | 0x00020000 | 00000000 00000010... | -| kp_b | Prefix | any | 0x00030000 | 00000000 00000011... | -| kp_f | Postfix, Upper | float32, float64 | 0x00040000 | 00000000 00000100... | -| kp_c | | char | 0x00050000 | 00000000 00000101... | -| kp_sing | | char* | 0x00060000 | 00000000 00000110... | +| format | possible flags | data types | hex value | bin value | +|-----------|----------------|------------|------------|-----------| +| kp_i | | i8... i64 | 0x00000000 | 00000000 00000000... | +| kp_u | Postfix, Upper | u8... u64 | 0x00010000 | 00000000 00000001... | +| kp_h | Prefix, Upper | any | 0x00020000 | 00000000 00000010... | +| kp_b | Prefix | any | 0x00030000 | 00000000 00000011... | +| kp_f | Postfix, Upper | f32, f64 | 0x00040000 | 00000000 00000100... | +| kp_c | | char | 0x00050000 | 00000000 00000101... | +| kp_string | | char* | 0x00060000 | 00000000 00000110... | + +P.S. `any` means you must add `kpid` to `kp_fmt` if data type is not base type ### *Flags* | flag | hex value | bin value | diff --git a/src/kprint/kprintf.c b/src/kprint/kprintf.c index 261c649..52e8201 100644 --- a/src/kprint/kprintf.c +++ b/src/kprint/kprintf.c @@ -5,7 +5,7 @@ #if defined(_WIN64) || defined(_WIN32) #include -WORD unixColorToWin(uint8 c){ +WORD unixColorToWin(u8 c){ switch(c){ //foreground case 30: return 0; @@ -49,7 +49,7 @@ WORD unixColorToWin(uint8 c){ void kprintf(const char* format, ...){ va_list vl; va_start(vl, format); - uint32 i=0; + u32 i=0; for(char c=format[i++]; c!=0; c=format[i++]){ if(c=='%'){ char* argstr=NULL; @@ -58,18 +58,18 @@ void kprintf(const char* format, ...){ format_escape_seq: switch (c) { case 'u': - argstr=toString_uint( - l ? va_arg(vl, uint64) : va_arg(vl, uint32) + argstr=toString_u64( + l ? va_arg(vl, u64) : va_arg(vl, u32) ,0,0); break; case 'i': case 'd': - argstr=toString_int( - l ? va_arg(vl, int64) : va_arg(vl, int32) + argstr=toString_i64( + l ? va_arg(vl, i64) : va_arg(vl, i32) ); break; case 'f': - // float32 is promoted to float64 when passed through '...' - argstr=toString_float64(va_arg(vl, float64), toString_float_default_precision,0,0); + // f32 is promoted to f64 when passed through '...' + argstr=toString_f64(va_arg(vl, f64), toString_float_default_precision,0,0); break; case 'l': l=true; @@ -78,7 +78,7 @@ void kprintf(const char* format, ...){ break; case 'p': case 'x': ; - uint64 px=va_arg(vl, uint64); + u64 px=va_arg(vl, u64); argstr=toString_hex(&px,getEndian()==LittleEndian,sizeof(px),1,0); break; case 's': ; @@ -108,8 +108,8 @@ void kprintf(const char* format, ...){ IFWIN( ({ if((c=format[i++])=='['){ - uint8 colorUnix=0; - for(int8 n=0; n<6 && c!=0; n++){ + u8 colorUnix=0; + for(i8 n=0; n<6 && c!=0; n++){ c=format[i++]; switch (c){ case '0': case '1': case '2': case '3': case '4': diff --git a/src/random/krandom.h b/src/random/krandom.h index d78b7d6..2072260 100644 --- a/src/random/krandom.h +++ b/src/random/krandom.h @@ -12,8 +12,8 @@ extern "C" { /* You can choose any algorithm that has required functions: - some_alg32_statePtr some_alg32_init(uint32 seed); - uint32 some_alg32_next(some_alg32_statePtr); + some_alg32_statePtr some_alg32_init(u32 seed); + u32 some_alg32_next(some_alg32_statePtr); void some_alg32_free(some_alg32_statePtr); #define KRAND_ALG32_init some_alg32_init @@ -51,19 +51,19 @@ typedef void* krand_statePtr; #define __krand_next_definition(VALUE_SIZE) { return from+KRAND_ALG##VALUE_SIZE##_next(state)%(to-from); } // ready-to-use functions -static inline int8 krand_next8 (krand_statePtr state, int8 from, int8 to) __krand_next_definition(32) -static inline int16 krand_next16(krand_statePtr state, int16 from, int16 to) __krand_next_definition(32) -static inline int32 krand_next32(krand_statePtr state, int32 from, int32 to) __krand_next_definition(32) -static inline int64 krand_next64(krand_statePtr state, int64 from, int64 to) __krand_next_definition(64) +static inline i8 krand_next8 (krand_statePtr state, i8 from, i8 to) __krand_next_definition(32) +static inline i16 krand_next16(krand_statePtr state, i16 from, i16 to) __krand_next_definition(32) +static inline i32 krand_next32(krand_statePtr state, i32 from, i32 to) __krand_next_definition(32) +static inline i64 krand_next64(krand_statePtr state, i64 from, i64 to) __krand_next_definition(64) // divides random number by 2^64 to return a value between 0 and 1 -static inline float32 krand_nextFloat32(krand_statePtr state) {return (uint32)KRAND_ALG32_next(state)/0xffffffff; } -static inline float64 krand_nextFloat64(krand_statePtr state) {return KRAND_ALG64_next(state)/0xffffffff; } +static inline f32 krand_nextFloat32(krand_statePtr state) {return (u32)KRAND_ALG32_next(state)/0xffffffff; } +static inline f64 krand_nextFloat64(krand_statePtr state) {return KRAND_ALG64_next(state)/0xffffffff; } ///@param chance (0-1.0) is probability of success static inline bool fate(krand_statePtr state,float chance){ - int limit=1/chance + 0.01f; + i32 limit=1/chance + 0.01f; return KRAND_ALG32_next(state)%limit == 0; } diff --git a/src/random/splitmix64/splitmix64.c b/src/random/splitmix64/splitmix64.c index 591167c..c267b9e 100644 --- a/src/random/splitmix64/splitmix64.c +++ b/src/random/splitmix64/splitmix64.c @@ -13,18 +13,18 @@ generator. // The state can be seeded with any (upto) 64 bit integer value. -void* splitmix64_init(uint64 seed){ +void* splitmix64_init(u64 seed){ splitmix64_state* state=malloc(sizeof(splitmix64_state)); *state=seed; return state; } -uint64 splitmix64_next(void* _state) { +u64 splitmix64_next(void* _state) { splitmix64_state* state=_state; // increment the state variable *state += 0x9e3779b97f4a7c15; // copy the state to a working variable - uint64 z = *state; + u64 z = *state; // xor the variable with the variable right bit shifted 30 then multiply by a constant z = (z ^ (z>>30)) * 0xbf58476d1ce4e5b9; // xor the variable with the variable right bit shifted 27 then multiply by a constant diff --git a/src/random/splitmix64/splitmix64.h b/src/random/splitmix64/splitmix64.h index 8cf8104..3ffeb1a 100644 --- a/src/random/splitmix64/splitmix64.h +++ b/src/random/splitmix64/splitmix64.h @@ -6,13 +6,13 @@ extern "C" { #include "../../base/base.h" -typedef uint64 splitmix64_state; +typedef u64 splitmix64_state; typedef void* splitmix64_statePtr; -splitmix64_statePtr splitmix64_init(uint64 seed); +splitmix64_statePtr splitmix64_init(u64 seed); static inline splitmix64_statePtr splitmix64_initFromTime(void) { return splitmix64_init(time(NULL)); } -uint64 splitmix64_next(splitmix64_statePtr); +u64 splitmix64_next(splitmix64_statePtr); static inline void splitmix64_free(splitmix64_statePtr state) { free(state); } diff --git a/src/random/xoroshiro/32bitValue/xoroshiro64.h b/src/random/xoroshiro/32bitValue/xoroshiro64.h index 6377bba..680a926 100644 --- a/src/random/xoroshiro/32bitValue/xoroshiro64.h +++ b/src/random/xoroshiro/32bitValue/xoroshiro64.h @@ -8,12 +8,12 @@ extern "C" { #include "../../splitmix64/splitmix64.h" typedef union { - uint64 merged; - uint32 s[2]; + u64 merged; + u32 s[2]; } xoroshiro64_state; typedef void* xoroshiro64_statePtr; -xoroshiro64_statePtr xoroshiro64_init(uint64 seed); +xoroshiro64_statePtr xoroshiro64_init(u64 seed); #define xoroshiro64star_init xoroshiro64_init #define xoroshiro64starstar_init xoroshiro64_init @@ -21,8 +21,8 @@ static inline xoroshiro64_statePtr xoroshiro64_initFromTime(void) { return xoros #define xoroshiro64star_initFromTime xoroshiro64_initFromTime #define xoroshiro64starstar_initFromTime xoroshiro64_initFromTime -uint32 xoroshiro64star_next(xoroshiro64_statePtr); -uint32 xoroshiro64starstar_next(xoroshiro64_statePtr); +u32 xoroshiro64star_next(xoroshiro64_statePtr); +u32 xoroshiro64starstar_next(xoroshiro64_statePtr); static inline void xoroshiro64_free(xoroshiro64_statePtr state) { free(state); diff --git a/src/random/xoroshiro/32bitValue/xoroshiro64star.c b/src/random/xoroshiro/32bitValue/xoroshiro64star.c index 7c2fd3c..ca57d35 100644 --- a/src/random/xoroshiro/32bitValue/xoroshiro64star.c +++ b/src/random/xoroshiro/32bitValue/xoroshiro64star.c @@ -10,8 +10,8 @@ See . */ /* This is xoroshiro64* 1.0, our best and fastest 32-bit small-state -generator for 32-bit floating-point numbers. We suggest to use its -upper bits for floating-point generation, as it is slightly faster than +generator for 32-bit floating-poi32 numbers. We suggest to use its +upper bits for floating-poi32 generation, as it is slightly faster than xoroshiro64**. It passes all tests we are aware of except for linearity tests, as the lowest six bits have low linear complexity, so if low linear complexity is not considered an issue (as it is usually the @@ -23,15 +23,15 @@ right shifts to extract subsets of bits. The state must be seeded so that it is not everywhere zero. */ -static inline uint32 rotl(const uint32 x, int k) { +static inline u32 rotl(const u32 x, i32 k) { return (x << k) | (x >> (32 - k)); } -uint32 xoroshiro64star_next(void* _state) { +u32 xoroshiro64star_next(void* _state) { xoroshiro64_state* state=_state; - const uint32 s0 = state->s[0]; - uint32 s1 = state->s[1]; - const uint32 result = s0 * 0x9E3779BB; + const u32 s0 = state->s[0]; + u32 s1 = state->s[1]; + const u32 result = s0 * 0x9E3779BB; s1 ^= s0; state->s[0] = rotl(s0, 26) ^ s1 ^ (s1 << 9); // a, b @@ -40,7 +40,7 @@ uint32 xoroshiro64star_next(void* _state) { return result; } -void* xoroshiro64_init(uint64 seed){ +void* xoroshiro64_init(u64 seed){ xoroshiro64_state* state=malloc(sizeof(xoroshiro64_state)); splitmix64_state* splitmix=splitmix64_init(seed); state->merged=splitmix64_next(splitmix); diff --git a/src/random/xoroshiro/32bitValue/xoroshiro64starstar.c b/src/random/xoroshiro/32bitValue/xoroshiro64starstar.c index df4432e..40d93fc 100644 --- a/src/random/xoroshiro/32bitValue/xoroshiro64starstar.c +++ b/src/random/xoroshiro/32bitValue/xoroshiro64starstar.c @@ -19,15 +19,15 @@ See . */ The state must be seeded so that it is not everywhere zero. */ -static inline uint32 rotl(const uint32 x, int k) { +static inline u32 rotl(const u32 x, i32 k) { return (x << k) | (x >> (32 - k)); } -uint32 xoroshiro64starstar_next(void* _state) { +u32 xoroshiro64starstar_next(void* _state) { xoroshiro64_state* state=_state; - const uint32 s0 = state->s[0]; - uint32 s1 = state->s[1]; - const uint32 result = rotl(s0 * 0x9E3779BB, 5) * 5; + const u32 s0 = state->s[0]; + u32 s1 = state->s[1]; + const u32 result = rotl(s0 * 0x9E3779BB, 5) * 5; s1 ^= s0; state->s[0] = rotl(s0, 26) ^ s1 ^ (s1 << 9); // a, b diff --git a/src/random/xoroshiro/64bitValue/xoroshiro128.h b/src/random/xoroshiro/64bitValue/xoroshiro128.h index 63ed537..33b7116 100644 --- a/src/random/xoroshiro/64bitValue/xoroshiro128.h +++ b/src/random/xoroshiro/64bitValue/xoroshiro128.h @@ -9,11 +9,11 @@ extern "C" { typedef union { - uint32 s[2]; + u32 s[2]; } xoroshiro128_state; typedef void* xoroshiro128_statePtr; -xoroshiro128_statePtr xoroshiro128_init(uint64 seed); +xoroshiro128_statePtr xoroshiro128_init(u64 seed); #define xoroshiro128plus_init xoroshiro128_init #define xoroshiro128plusplus_init xoroshiro128_init #define xoroshiro128starstar_init xoroshiro128_init @@ -23,9 +23,9 @@ static inline xoroshiro128_statePtr xoroshiro128_initFromTime(void) { return xor #define xoroshiro128plusplus_initFromTime xoroshiro128_initFromTime #define xoroshiro128starstar_initFromTime xoroshiro128_initFromTime -uint64 xoroshiro128plus_next(xoroshiro128_statePtr); -uint64 xoroshiro128plusplus_next(xoroshiro128_statePtr); -uint64 xoroshiro128starstar_next(xoroshiro128_statePtr); +u64 xoroshiro128plus_next(xoroshiro128_statePtr); +u64 xoroshiro128plusplus_next(xoroshiro128_statePtr); +u64 xoroshiro128starstar_next(xoroshiro128_statePtr); static inline void xoroshiro128_free(xoroshiro128_statePtr state) { free(state); diff --git a/src/random/xoroshiro/64bitValue/xoroshiro128plus.c b/src/random/xoroshiro/64bitValue/xoroshiro128plus.c index e01e0b5..05760ec 100644 --- a/src/random/xoroshiro/64bitValue/xoroshiro128plus.c +++ b/src/random/xoroshiro/64bitValue/xoroshiro128plus.c @@ -9,9 +9,9 @@ See . */ #include "xoroshiro128.h" /* This is xoroshiro128+ 1.0, our best and fastest small-state generator - for floating-point numbers, but its state space is large enough only + for floating-poi32 numbers, but its state space is large enough only for mild parallelism. We suggest to use its upper bits for - floating-point generation, as it is slightly faster than + floating-poi32 generation, as it is slightly faster than xoroshiro128++/xoroshiro128**. It passes all tests we are aware of except for the four lower bits, which might fail linearity tests (and just those), so if low linear complexity is not considered an issue (as @@ -32,15 +32,15 @@ See . */ better results in our test than the 2016 version (a=55, b=14, c=36). */ -static inline uint64 rotl(const uint64 x, int k) { +static inline u64 rotl(const u64 x, i32 k) { return (x << k) | (x >> (64 - k)); } -uint64 xoroshiro128plus_next(void* _state){ +u64 xoroshiro128plus_next(void* _state){ xoroshiro128_state* state=_state; - const uint64 s0 = state->s[0]; - uint64 s1 = state->s[1]; - const uint64 result = s0 + s1; + const u64 s0 = state->s[0]; + u64 s1 = state->s[1]; + const u64 result = s0 + s1; s1 ^= s0; state->s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b @@ -49,7 +49,7 @@ uint64 xoroshiro128plus_next(void* _state){ return result; } -void* xoroshiro128_init(uint64 seed){ +void* xoroshiro128_init(u64 seed){ xoroshiro128_state* state=malloc(sizeof(xoroshiro128_state)); splitmix64_state* splitmix=splitmix64_init(seed); state->s[0]=splitmix64_next(splitmix); diff --git a/src/random/xoroshiro/64bitValue/xoroshiro128plusplus.c b/src/random/xoroshiro/64bitValue/xoroshiro128plusplus.c index c01fb30..43e110e 100644 --- a/src/random/xoroshiro/64bitValue/xoroshiro128plusplus.c +++ b/src/random/xoroshiro/64bitValue/xoroshiro128plusplus.c @@ -13,7 +13,7 @@ See . */ tests we are aware of, but its state space is large enough only for mild parallelism. - For generating just floating-point numbers, xoroshiro128+ is even + For generating just floating-poi32 numbers, xoroshiro128+ is even faster (but it has a very mild bias, see notes in the comments). The state must be seeded so that it is not everywhere zero. If you have @@ -21,15 +21,15 @@ See . */ output to fill s. */ -static inline uint64 rotl(const uint64 x, int k) { +static inline u64 rotl(const u64 x, i32 k) { return (x << k) | (x >> (64 - k)); } -uint64 xoroshiro128plusplus_next(void* _state){ +u64 xoroshiro128plusplus_next(void* _state){ xoroshiro128_state* state=_state; - const uint64 s0 = state->s[0]; - uint64 s1 = state->s[1]; - const uint64 result = rotl(s0 + s1, 17) + s0; + const u64 s0 = state->s[0]; + u64 s1 = state->s[1]; + const u64 result = rotl(s0 + s1, 17) + s0; s1 ^= s0; state->s[0] = rotl(s0, 49) ^ s1 ^ (s1 << 21); // a, b diff --git a/src/random/xoroshiro/64bitValue/xoroshiro128starstar.c b/src/random/xoroshiro/64bitValue/xoroshiro128starstar.c index 3e9ac72..5e25851 100644 --- a/src/random/xoroshiro/64bitValue/xoroshiro128starstar.c +++ b/src/random/xoroshiro/64bitValue/xoroshiro128starstar.c @@ -13,7 +13,7 @@ See . */ tests we are aware of, but its state space is large enough only for mild parallelism. - For generating just floating-point numbers, xoroshiro128+ is even + For generating just floating-poi32 numbers, xoroshiro128+ is even faster (but it has a very mild bias, see notes in the comments). The state must be seeded so that it is not everywhere zero. If you have @@ -21,15 +21,15 @@ See . */ output to fill s. */ -static inline uint64 rotl(const uint64 x, int k) { +static inline u64 rotl(const u64 x, i32 k) { return (x << k) | (x >> (64 - k)); } -uint64 xoroshiro128starstar_next(void* _state){ +u64 xoroshiro128starstar_next(void* _state){ xoroshiro128_state* state=_state; - const uint64 s0 = state->s[0]; - uint64 s1 = state->s[1]; - const uint64 result = rotl(s0 * 5, 7) * 9; + const u64 s0 = state->s[0]; + u64 s1 = state->s[1]; + const u64 result = rotl(s0 * 5, 7) * 9; s1 ^= s0; state->s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b diff --git a/src/random/xoshiro/32bitValue/xoshiro128.h b/src/random/xoshiro/32bitValue/xoshiro128.h index 02d52e8..daf2333 100644 --- a/src/random/xoshiro/32bitValue/xoshiro128.h +++ b/src/random/xoshiro/32bitValue/xoshiro128.h @@ -9,12 +9,12 @@ extern "C" { typedef union { - uint64 merged[2]; - uint32 s[4]; + u64 merged[2]; + u32 s[4]; } xoshiro128_state; typedef void* xoshiro128_statePtr; -xoshiro128_statePtr xoshiro128_init(uint64 seed); +xoshiro128_statePtr xoshiro128_init(u64 seed); #define xoshiro128plus_init xoshiro128_init #define xoshiro128plusplus_init xoshiro128_init #define xoshiro128starstar_init xoshiro128_init @@ -24,9 +24,9 @@ static inline xoshiro128_statePtr xoshiro128_initFromTime(void) { return xoshiro #define xoshiro128plusplus_initFromTime xoshiro128_initFromTime #define xoshiro128starstar_initFromTime xoshiro128_initFromTime -uint32 xoshiro128plus_next(xoshiro128_statePtr); -uint32 xoshiro128plusplus_next(xoshiro128_statePtr); -uint32 xoshiro128starstar_next(xoshiro128_statePtr); +u32 xoshiro128plus_next(xoshiro128_statePtr); +u32 xoshiro128plusplus_next(xoshiro128_statePtr); +u32 xoshiro128starstar_next(xoshiro128_statePtr); static inline void xoshiro128_free(xoshiro128_statePtr state) { free(state); diff --git a/src/random/xoshiro/32bitValue/xoshiro128plus.c b/src/random/xoshiro/32bitValue/xoshiro128plus.c index 8cafc8b..f68b3d5 100644 --- a/src/random/xoshiro/32bitValue/xoshiro128plus.c +++ b/src/random/xoshiro/32bitValue/xoshiro128plus.c @@ -9,8 +9,8 @@ See . */ #include "xoshiro128.h" /* This is xoshiro128+ 1.0, our best and fastest 32-bit generator for 32-bit - floating-point numbers. We suggest to use its upper bits for - floating-point generation, as it is slightly faster than xoshiro128**. + floating-poi32 numbers. We suggest to use its upper bits for + floating-poi32 generation, as it is slightly faster than xoshiro128**. It passes all tests we are aware of except for linearity tests, as the lowest four bits have low linear complexity, so if low linear complexity is not considered an issue (as it is usually @@ -22,15 +22,15 @@ See . */ The state must be seeded so that it is not everywhere zero. */ -static inline uint32 rotl(const uint32 x, int k) { +static inline u32 rotl(const u32 x, i32 k) { return (x << k) | (x >> (32 - k)); } -uint32 xoshiro128plus_next(void* _state){ +u32 xoshiro128plus_next(void* _state){ xoshiro128_state* state=_state; - const uint32 result = state->s[0] + state->s[3]; + const u32 result = state->s[0] + state->s[3]; - const uint32 t = state->s[1] << 9; + const u32 t = state->s[1] << 9; state->s[2] ^= state->s[0]; state->s[3] ^= state->s[1]; @@ -44,7 +44,7 @@ uint32 xoshiro128plus_next(void* _state){ return result; } -void* xoshiro128_init(uint64 seed){ +void* xoshiro128_init(u64 seed){ xoshiro128_state* state=malloc(sizeof(xoshiro128_state)); splitmix64_state* splitmix=splitmix64_init(seed); state->merged[0]=splitmix64_next(splitmix); diff --git a/src/random/xoshiro/32bitValue/xoshiro128plusplus.c b/src/random/xoshiro/32bitValue/xoshiro128plusplus.c index e9be19d..8fea492 100644 --- a/src/random/xoshiro/32bitValue/xoshiro128plusplus.c +++ b/src/random/xoshiro/32bitValue/xoshiro128plusplus.c @@ -19,15 +19,15 @@ See . */ The state must be seeded so that it is not everywhere zero. */ -static inline uint32 rotl(const uint32 x, int k) { +static inline u32 rotl(const u32 x, i32 k) { return (x << k) | (x >> (32 - k)); } -uint32 xoshiro128plusplus_next(void* _state){ +u32 xoshiro128plusplus_next(void* _state){ xoshiro128_state* state=_state; - const uint32 result = rotl(state->s[0] + state->s[3], 7) + state->s[0]; + const u32 result = rotl(state->s[0] + state->s[3], 7) + state->s[0]; - const uint32 t = state->s[1] << 9; + const u32 t = state->s[1] << 9; state->s[2] ^= state->s[0]; state->s[3] ^= state->s[1]; diff --git a/src/random/xoshiro/32bitValue/xoshiro128starstar.c b/src/random/xoshiro/32bitValue/xoshiro128starstar.c index 40a53d2..87a20bc 100644 --- a/src/random/xoshiro/32bitValue/xoshiro128starstar.c +++ b/src/random/xoshiro/32bitValue/xoshiro128starstar.c @@ -22,15 +22,15 @@ See . */ The state must be seeded so that it is not everywhere zero. */ -static inline uint32 rotl(const uint32 x, int k) { +static inline u32 rotl(const u32 x, i32 k) { return (x << k) | (x >> (32 - k)); } -uint32 xoshiro128starstar_next(void* _state){ +u32 xoshiro128starstar_next(void* _state){ xoshiro128_state* state=_state; - const uint32 result = rotl(state->s[1] * 5, 7) * 9; + const u32 result = rotl(state->s[1] * 5, 7) * 9; - const uint32 t = state->s[1] << 9; + const u32 t = state->s[1] << 9; state->s[2] ^= state->s[0]; state->s[3] ^= state->s[1]; diff --git a/src/random/xoshiro/64bitValue/xoshiro256.h b/src/random/xoshiro/64bitValue/xoshiro256.h index 479c6aa..263d75e 100644 --- a/src/random/xoshiro/64bitValue/xoshiro256.h +++ b/src/random/xoshiro/64bitValue/xoshiro256.h @@ -9,11 +9,11 @@ extern "C" { typedef union { - uint64 s[4]; + u64 s[4]; } xoshiro256_state; typedef void* xoshiro256_statePtr; -xoshiro256_statePtr xoshiro256_init(uint64 seed); +xoshiro256_statePtr xoshiro256_init(u64 seed); #define xoshiro256plus_init xoshiro256_init #define xoshiro256plusplus_init xoshiro256_init #define xoshiro256starstar_init xoshiro256_init @@ -23,9 +23,9 @@ static inline xoshiro256_statePtr xoshiro256_initFromTime(void) { return xoshiro #define xoshiro256plusplus_initFromTime xoshiro256_initFromTime #define xoshiro256starstar_initFromTime xoshiro256_initFromTime -uint64 xoshiro256plus_next(xoshiro256_statePtr); -uint64 xoshiro256plusplus_next(xoshiro256_statePtr); -uint64 xoshiro256starstar_next(xoshiro256_statePtr); +u64 xoshiro256plus_next(xoshiro256_statePtr); +u64 xoshiro256plusplus_next(xoshiro256_statePtr); +u64 xoshiro256starstar_next(xoshiro256_statePtr); static inline void xoshiro256_free(xoshiro256_statePtr state) { free(state); diff --git a/src/random/xoshiro/64bitValue/xoshiro256plus.c b/src/random/xoshiro/64bitValue/xoshiro256plus.c index 066ef8a..ee7ae32 100644 --- a/src/random/xoshiro/64bitValue/xoshiro256plus.c +++ b/src/random/xoshiro/64bitValue/xoshiro256plus.c @@ -24,15 +24,15 @@ See . */ output to fill s. */ -static inline uint64 rotl(const uint64 x, int k) { +static inline u64 rotl(const u64 x, i32 k) { return (x << k) | (x >> (64 - k)); } -uint64 xoshiro256plus_next(void* _state){ +u64 xoshiro256plus_next(void* _state){ xoshiro256_state* state=_state; - const uint64 result = state->s[0] + state->s[3]; + const u64 result = state->s[0] + state->s[3]; - const uint64 t = state->s[1] << 17; + const u64 t = state->s[1] << 17; state->s[2] ^= state->s[0]; state->s[3] ^= state->s[1]; @@ -46,7 +46,7 @@ uint64 xoshiro256plus_next(void* _state){ return result; } -void* xoshiro256_init(uint64 seed){ +void* xoshiro256_init(u64 seed){ xoshiro256_state* state=malloc(sizeof(xoshiro256_state)); splitmix64_state* splitmix=splitmix64_init(seed); state->s[0]=splitmix64_next(splitmix); diff --git a/src/random/xoshiro/64bitValue/xoshiro256plusplus.c b/src/random/xoshiro/64bitValue/xoshiro256plusplus.c index 77ca943..d28eb7c 100644 --- a/src/random/xoshiro/64bitValue/xoshiro256plusplus.c +++ b/src/random/xoshiro/64bitValue/xoshiro256plusplus.c @@ -13,20 +13,20 @@ See . */ enough for any parallel application, and it passes all tests we are aware of. - For generating just floating-point numbers, xoshiro256+ is even faster. + For generating just floating-poi32 numbers, xoshiro256+ is even faster. The state must be seeded so that it is not everywhere zero. If you have a 64-bit seed, we suggest to seed a splitmix64 generator and use its output to fill s. */ -static inline uint64 rotl(const uint64 x, int k) { +static inline u64 rotl(const u64 x, i32 k) { return (x << k) | (x>>(64 - k)); } -uint64 xoshiro256plusplus_next(void* _state) { +u64 xoshiro256plusplus_next(void* _state) { xoshiro256_state* state=_state; - const uint64 result=rotl(state->s[0] + state->s[3], 23) + state->s[0]; - const uint64 t=state->s[1] << 17; + const u64 result=rotl(state->s[0] + state->s[3], 23) + state->s[0]; + const u64 t=state->s[1] << 17; state->s[2] ^= state->s[0]; state->s[3] ^= state->s[1]; state->s[1] ^= state->s[2]; diff --git a/src/random/xoshiro/64bitValue/xoshiro256starstar.c b/src/random/xoshiro/64bitValue/xoshiro256starstar.c index 7829096..804007c 100644 --- a/src/random/xoshiro/64bitValue/xoshiro256starstar.c +++ b/src/random/xoshiro/64bitValue/xoshiro256starstar.c @@ -13,21 +13,21 @@ See . */ large enough for any parallel application, and it passes all tests we are aware of. - For generating just floating-point numbers, xoshiro256+ is even faster. + For generating just floating-poi32 numbers, xoshiro256+ is even faster. The state must be seeded so that it is not everywhere zero. If you have a 64-bit seed, we suggest to seed a splitmix64 generator and use its output to fill s. */ -static inline uint64 rotl(const uint64 x, int k) { +static inline u64 rotl(const u64 x, i32 k) { return (x << k) | (x >> (64 - k)); } -uint64 xoshiro256starstar_next(void* _state){ +u64 xoshiro256starstar_next(void* _state){ xoshiro256_state* state=_state; - const uint64 result = rotl(state->s[1] * 5, 7) * 9; + const u64 result = rotl(state->s[1] * 5, 7) * 9; - const uint64 t = state->s[1] << 17; + const u64 t = state->s[1] << 17; state->s[2] ^= state->s[0]; state->s[3] ^= state->s[1]; diff --git a/tests/main.cpp b/tests/main.cpp index 9c43add..14e310c 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,6 +1,6 @@ #include "tests.h" -int main(){ +i32 main(){ if(!setlocale(LC_ALL, "C.UTF8")) kprintf("\e[93msetlocale failed\n"); ktDescriptors_beginInit(); diff --git a/tests/test_autoarr-vs-vector.cpp b/tests/test_autoarr-vs-vector.cpp index 1ea747d..c85675b 100644 --- a/tests/test_autoarr-vs-vector.cpp +++ b/tests/test_autoarr-vs-vector.cpp @@ -2,16 +2,16 @@ #include "../src/Autoarr/Autoarr.h" #include -int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){ - uint32 count=blockLength*blockCount; - kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count); - Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength); - std::vector vec=std::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); + std::vector vec=std::vector(); optime("Autoarr_add", count, Autoarr_add(ar, op_i)); optime("vector_push_back", count, vec.push_back(op_i)); - int64 t=0; + i64 t=0; optime("Autoarr_get", count, t=Autoarr_get(ar, op_i)); optime("vector_get", count, diff --git a/tests/test_autoarr.c b/tests/test_autoarr.c index 2b3d24d..3e468fb 100644 --- a/tests/test_autoarr.c +++ b/tests/test_autoarr.c @@ -1,8 +1,8 @@ #include "tests.h" #include "../src/Autoarr/Autoarr.h" -static void printautoarr(Autoarr(uint16)* ar){ - kprintf("\e[94mAutoarr(uint16): " +static void printautoarr(Autoarr(u16)* ar){ + kprintf("\e[94mAutoarr(u16): " IFWIN("%llu", "%lu") "\n max_blocks_count: %u\n" " blocks_count: %u\n" @@ -10,7 +10,7 @@ static void printautoarr(Autoarr(uint16)* ar){ " block_length: %u\n" " max_length: %u\n" " length: %u\n", - sizeof(Autoarr(uint16)), + sizeof(Autoarr(u16)), ar->max_blocks_count, ar->blocks_count, ar->max_block_length, @@ -19,18 +19,18 @@ static void printautoarr(Autoarr(uint16)* ar){ Autoarr_length(ar)); } -static void fillar(Autoarr(uint16)* ar){ - for (uint16 i=0;irows[h]; - uint32 l=Autoarr_length(ar); + u32 l=Autoarr_length(ar); lgs[l]++; } - for(uint32 i=0; i0) { char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2)); char* str1=char_multiply(' ',lgs[i]>=100?0:(lgs[i]>=10?1:2)); @@ -36,7 +36,7 @@ void printrowgraph(Hashtable* ht){ } } -char* genkey(uint32 i){ +char* genkey(u32 i){ char* key=malloc(12); IFMSC( sprintf_s(key,12,"key_%u",i), @@ -46,13 +46,13 @@ char* genkey(uint32 i){ } void fill(Hashtable* ht){ - for(uint32 i=0;i<100000;i++) + for(u32 i=0;i<100000;i++) Hashtable_add(ht,genkey(i),UniUInt64(i)); } Unitype gett(Hashtable* ht){ Unitype u; - for(uint32 i=0;i<100000;i++){ + for(u32 i=0;i<100000;i++){ char* key=genkey(i); u=Hashtable_get(ht,key); free(key); diff --git a/tests/test_kprint.c b/tests/test_kprint.c index 587ff59..9da6553 100644 --- a/tests/test_kprint.c +++ b/tests/test_kprint.c @@ -5,7 +5,7 @@ void test_kprint(){ //int kprint(kp_fgCyan| kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n"); - //uint + //u kprint(kp_fgGreen| kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ', kp_u,1234567890987654321LL, kp_c,'\n'); @@ -15,7 +15,7 @@ void test_kprint(){ kp_f,-1.0f, kp_c,' ', kp_f,0.0f, kp_c,' ', kp_f,1.0f, kp_c,'\n', kp_f|kp_post,0.000020004f, kp_c,' ', kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n'); - //double + //f64 kprint(kp_fgYellowD| kp_f,-4000.0109, kp_c,' ', kp_f,-0.000020004, kp_c,'\n', kp_f,-1.0, kp_c,' ', kp_f,0.0, kp_c,' ', kp_f,1.0, kp_c,'\n', diff --git a/tests/test_kprint_colors.c b/tests/test_kprint_colors.c index b397e21..4c97447 100644 --- a/tests/test_kprint_colors.c +++ b/tests/test_kprint_colors.c @@ -16,13 +16,13 @@ void test_kprint_colors(){ /* IFWIN( ({ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - for(uint8 col=0; col<255; col++){ + for(u8 col=0; col<255; col++){ SetConsoleTextAttribute(hConsole, col); kprintf("%u ",col); } }), ({ - for(uint8 col=0; col<255; col++) + for(u8 col=0; col<255; col++) kprintf("\e[%um%u ", col, col); }) ); diff --git a/tests/test_rng_algorithms.c b/tests/test_rng_algorithms.c index 1af5ef5..23e8ab9 100644 --- a/tests/test_rng_algorithms.c +++ b/tests/test_rng_algorithms.c @@ -5,18 +5,18 @@ #define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){\ kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n");\ void* s= ALG##_init(0);\ - uint##VALUE_SIZE r=ALG##_next(s);\ + u##VALUE_SIZE r=ALG##_next(s);\ kprintf("\e[97m next from zero seed:");\ if(r!=EXPECTED_FROM_ZERO){\ - kprintf("\e[91m " IFWIN("%llu\n","%lu\n"), (uint64)r);\ + kprintf("\e[91m " IFWIN("%llu\n","%lu\n"), (u64)r);\ throw(ERR_UNEXPECTEDVAL);\ }\ - kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)r);\ + kprintf("\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r);\ ALG##_free(s);\ s= ALG##_initFromTime();\ r=ALG##_next(s);\ ALG##_free(s);\ - kprintf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (uint64)r);\ + kprintf("\e[97m next from time seed:\e[92m " IFWIN("%llu\n","%lu\n"), (u64)r);\ } void test_rng_algorithms(){ diff --git a/tests/test_searchtree.c b/tests/test_searchtree.c index 656a96a..d315e50 100644 --- a/tests/test_searchtree.c +++ b/tests/test_searchtree.c @@ -9,13 +9,13 @@ void printstnode(STNode* node){ kprintf("\n"); // prints pointers to all existing branches /* kprintf(" branches: %p\n", node->branches); - if(node->branches) for(uint8 i=0;i<8;i++){ + if(node->branches) for(u8 i=0;i<8;i++){ kprintf(" \e[90m[%u]=%p\n",i,node->branches[i]); if(node->branches[i]) - for (uint8 ii = 0; ii < 8; ii++){ + for (u8 ii = 0; ii < 8; ii++){ kprintf(" \e[90m[%u]=%p\n",ii,node->branches[i][ii]); if(node->branches[i][ii]) - for (uint8 iii = 0; iii < 4; iii++) + for (u8 iii = 0; iii < 4; iii++) kprintf(" \e[90m[%u]=%p\n",iii,node->branches[i][ii][iii]); }