i32
This commit is contained in:
@@ -2,21 +2,21 @@
|
|||||||
|
|
||||||
Array_define(char)
|
Array_define(char)
|
||||||
Array_define(bool)
|
Array_define(bool)
|
||||||
Array_define(float32)
|
Array_define(f32)
|
||||||
Array_define(float64)
|
Array_define(f64)
|
||||||
Array_define(int8)
|
Array_define(i8)
|
||||||
Array_define(uint8)
|
Array_define(u8)
|
||||||
Array_define(int16)
|
Array_define(i16)
|
||||||
Array_define(uint16)
|
Array_define(u16)
|
||||||
Array_define(int32)
|
Array_define(i32)
|
||||||
Array_define(uint32)
|
Array_define(u32)
|
||||||
Array_define(int64)
|
Array_define(i64)
|
||||||
Array_define(uint64)
|
Array_define(u64)
|
||||||
|
|
||||||
Array_define(Unitype)
|
Array_define(Unitype)
|
||||||
|
|
||||||
void Array_Unitype_free_(Array_Unitype* array, bool freeMembers){
|
void Array_Unitype_free_(Array_Unitype* array, bool freeMembers){
|
||||||
if(freeMembers) for (int32 i=0; i<array->length; i++)
|
if(freeMembers) for (i32 i=0; i<array->length; i++)
|
||||||
Unitype_free(array->values[i]);
|
Unitype_free(array->values[i]);
|
||||||
if(array->allocatedOnHeap)
|
if(array->allocatedOnHeap)
|
||||||
free(array->values);
|
free(array->values);
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ extern "C" {
|
|||||||
|
|
||||||
Array_declare(char)
|
Array_declare(char)
|
||||||
Array_declare(bool)
|
Array_declare(bool)
|
||||||
Array_declare(float32)
|
Array_declare(f32)
|
||||||
Array_declare(float64)
|
Array_declare(f64)
|
||||||
Array_declare(int8)
|
Array_declare(i8)
|
||||||
Array_declare(uint8)
|
Array_declare(u8)
|
||||||
Array_declare(int16)
|
Array_declare(i16)
|
||||||
Array_declare(uint16)
|
Array_declare(u16)
|
||||||
Array_declare(int32)
|
Array_declare(i32)
|
||||||
Array_declare(uint32)
|
Array_declare(u32)
|
||||||
Array_declare(int64)
|
Array_declare(i64)
|
||||||
Array_declare(uint64)
|
Array_declare(u64)
|
||||||
|
|
||||||
Array_declare(Unitype)
|
Array_declare(Unitype)
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ extern "C" {
|
|||||||
#define Array_declare(type)\
|
#define Array_declare(type)\
|
||||||
typedef struct Array_##type{\
|
typedef struct Array_##type{\
|
||||||
type* values;\
|
type* values;\
|
||||||
uint32 length;\
|
u32 length;\
|
||||||
bool allocatedOnHeap;\
|
bool allocatedOnHeap;\
|
||||||
} Array_##type;\
|
} Array_##type;\
|
||||||
\
|
\
|
||||||
ktid_declare(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) {\
|
return (Array_##type) {\
|
||||||
.values=(type*)malloc(sizeof(type)*length),\
|
.values=(type*)malloc(sizeof(type)*length),\
|
||||||
.length=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) {\
|
return (Array_##type) {\
|
||||||
.values=buffer,\
|
.values=buffer,\
|
||||||
.length=bufferLength,\
|
.length=bufferLength,\
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
Autoarr_define(char)
|
Autoarr_define(char)
|
||||||
Autoarr_define(bool)
|
Autoarr_define(bool)
|
||||||
Autoarr_define(float32)
|
Autoarr_define(f32)
|
||||||
Autoarr_define(float64)
|
Autoarr_define(f64)
|
||||||
Autoarr_define(uint8)
|
Autoarr_define(u8)
|
||||||
Autoarr_define(int8)
|
Autoarr_define(i8)
|
||||||
Autoarr_define(uint16)
|
Autoarr_define(u16)
|
||||||
Autoarr_define(int16)
|
Autoarr_define(i16)
|
||||||
Autoarr_define(uint32)
|
Autoarr_define(u32)
|
||||||
Autoarr_define(int32)
|
Autoarr_define(i32)
|
||||||
Autoarr_define(uint64)
|
Autoarr_define(u64)
|
||||||
Autoarr_define(int64)
|
Autoarr_define(i64)
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ extern "C" {
|
|||||||
|
|
||||||
Autoarr_declare(char)
|
Autoarr_declare(char)
|
||||||
Autoarr_declare(bool)
|
Autoarr_declare(bool)
|
||||||
Autoarr_declare(float32)
|
Autoarr_declare(f32)
|
||||||
Autoarr_declare(float64)
|
Autoarr_declare(f64)
|
||||||
Autoarr_declare(int8)
|
Autoarr_declare(i8)
|
||||||
Autoarr_declare(uint8)
|
Autoarr_declare(u8)
|
||||||
Autoarr_declare(int16)
|
Autoarr_declare(i16)
|
||||||
Autoarr_declare(uint16)
|
Autoarr_declare(u16)
|
||||||
Autoarr_declare(int32)
|
Autoarr_declare(i32)
|
||||||
Autoarr_declare(uint32)
|
Autoarr_declare(u32)
|
||||||
Autoarr_declare(int64)
|
Autoarr_declare(i64)
|
||||||
Autoarr_declare(uint64)
|
Autoarr_declare(u64)
|
||||||
|
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ extern "C" {
|
|||||||
#include "Autoarr.h"
|
#include "Autoarr.h"
|
||||||
#include "../Hashtable/KeyValuePair.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);
|
*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);
|
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);
|
*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);
|
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);
|
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);
|
*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);
|
*output=Autoarr_max_length(ar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ void ____Autoarr_free_Unitype_(void* ar);
|
|||||||
#define Autoarr_foreach(ar,elem,codeblock)({\
|
#define Autoarr_foreach(ar,elem,codeblock)({\
|
||||||
if(ar->blocks_count>0) {\
|
if(ar->blocks_count>0) {\
|
||||||
typeof(**ar->values) elem;\
|
typeof(**ar->values) elem;\
|
||||||
for(uint32 blockI=0;blockI<ar->blocks_count-1;blockI++)\
|
for(u32 blockI=0;blockI<ar->blocks_count-1;blockI++)\
|
||||||
for(uint32 elemI=0;elemI<ar->max_block_length;elemI++){\
|
for(u32 elemI=0;elemI<ar->max_block_length;elemI++){\
|
||||||
elem=ar->values[blockI][elemI];\
|
elem=ar->values[blockI][elemI];\
|
||||||
(codeblock);\
|
(codeblock);\
|
||||||
}\
|
}\
|
||||||
for(uint32 elemI=0;elemI<ar->block_length;elemI++){\
|
for(u32 elemI=0;elemI<ar->block_length;elemI++){\
|
||||||
elem=ar->values[ar->blocks_count-1][elemI];\
|
elem=ar->values[ar->blocks_count-1][elemI];\
|
||||||
(codeblock);\
|
(codeblock);\
|
||||||
}\
|
}\
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include "Autoarr.h"
|
#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);
|
*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);
|
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);
|
*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);
|
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);
|
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);
|
*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);
|
*output=Autoarr_max_length(ar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,25 +12,25 @@ struct Autoarr_##type;\
|
|||||||
\
|
\
|
||||||
typedef struct {\
|
typedef struct {\
|
||||||
void (*add)(struct Autoarr_##type* ar, type element);\
|
void (*add)(struct Autoarr_##type* ar, type element);\
|
||||||
type (*get)(struct Autoarr_##type* ar, uint32 index);\
|
type (*get)(struct Autoarr_##type* ar, u32 index);\
|
||||||
type* (*getptr)(struct Autoarr_##type* ar, uint32 index);\
|
type* (*getptr)(struct Autoarr_##type* ar, u32 index);\
|
||||||
void (*set)(struct Autoarr_##type* ar, uint32 index, type element);\
|
void (*set)(struct Autoarr_##type* ar, u32 index, type element);\
|
||||||
void (*freear)(struct Autoarr_##type* ar, bool freePtr);\
|
void (*freear)(struct Autoarr_##type* ar, bool freePtr);\
|
||||||
type* (*toArray)(struct Autoarr_##type* ar);\
|
type* (*toArray)(struct Autoarr_##type* ar);\
|
||||||
} __functions_list_t_##type;\
|
} __functions_list_t_##type;\
|
||||||
\
|
\
|
||||||
typedef struct Autoarr_##type{\
|
typedef struct Autoarr_##type{\
|
||||||
uint16 blocks_count;\
|
u16 blocks_count;\
|
||||||
uint16 max_blocks_count;\
|
u16 max_blocks_count;\
|
||||||
uint16 block_length;\
|
u16 block_length;\
|
||||||
uint16 max_block_length;\
|
u16 max_block_length;\
|
||||||
type** values;\
|
type** values;\
|
||||||
__functions_list_t_##type* functions;\
|
__functions_list_t_##type* functions;\
|
||||||
} Autoarr_##type;\
|
} Autoarr_##type;\
|
||||||
\
|
\
|
||||||
ktid_declare(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(Autoarr_##type* ar, bool freePtr);\
|
||||||
void ____Autoarr_free_##type(void* ar);
|
void ____Autoarr_free_##type(void* ar);
|
||||||
|
|
||||||
@@ -52,10 +52,10 @@ void ____Autoarr_free_##type(void* ar);
|
|||||||
autoarr->functions->toArray(autoarr)
|
autoarr->functions->toArray(autoarr)
|
||||||
|
|
||||||
#define Autoarr_length(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)
|
autoarr->max_block_length*(autoarr->blocks_count-1)+autoarr->block_length)
|
||||||
#define Autoarr_max_length(autoarr)\
|
#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){\
|
#define Autoarr_pop(AR){\
|
||||||
if(AR->block_length==1){\
|
if(AR->block_length==1){\
|
||||||
|
|||||||
@@ -26,23 +26,23 @@ create_block:\
|
|||||||
ar->block_length++;\
|
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);\
|
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX);\
|
||||||
return ar->values[index/ar->max_block_length][index%ar->max_block_length];\
|
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);\
|
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX);\
|
||||||
return ar->values[index/ar->max_block_length]+(index%ar->max_block_length);\
|
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);\
|
if(index>=Autoarr_length(ar)) throw(ERR_WRONGINDEX);\
|
||||||
ar->values[index/ar->max_block_length][index%ar->max_block_length]=element;\
|
ar->values[index/ar->max_block_length][index%ar->max_block_length]=element;\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
void __Autoarr_free_##type(Autoarr_##type* ar, bool freePtr){\
|
void __Autoarr_free_##type(Autoarr_##type* ar, bool freePtr){\
|
||||||
for(uint16 i=0; i<ar->blocks_count;i++)\
|
for(u16 i=0; i<ar->blocks_count;i++)\
|
||||||
free(ar->values[i]); \
|
free(ar->values[i]); \
|
||||||
free(ar->values);\
|
free(ar->values);\
|
||||||
if(freePtr) free(ar);\
|
if(freePtr) free(ar);\
|
||||||
@@ -52,9 +52,9 @@ void ____Autoarr_free_##type(void* ar){\
|
|||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
type* __Autoarr_toArray_##type(Autoarr_##type* ar){\
|
type* __Autoarr_toArray_##type(Autoarr_##type* ar){\
|
||||||
uint32 length=Autoarr_length(ar);\
|
u32 length=Autoarr_length(ar);\
|
||||||
type* array=malloc(length * sizeof(type));\
|
type* array=malloc(length * sizeof(type));\
|
||||||
for(uint32 i=0; i<length; i++)\
|
for(u32 i=0; i<length; i++)\
|
||||||
array[i]=__Autoarr_get_##type(ar, i);\
|
array[i]=__Autoarr_get_##type(ar, i);\
|
||||||
return array;\
|
return array;\
|
||||||
}\
|
}\
|
||||||
@@ -68,7 +68,7 @@ __functions_list_t_##type __functions_list_##type={\
|
|||||||
&__Autoarr_toArray_##type\
|
&__Autoarr_toArray_##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){\
|
||||||
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_blocks_count=max_blocks_count,\
|
||||||
|
|||||||
@@ -18,17 +18,17 @@ typedef struct DeserializeSharedData{
|
|||||||
|
|
||||||
|
|
||||||
// special func for throwing error messages about wrong characters in deserializing text
|
// special func for throwing error messages about wrong characters in deserializing text
|
||||||
Maybe ERROR_WRONGCHAR(const char c, char* _text, char* text_first, const char* srcfile, int line, const char* funcname){
|
Maybe ERROR_WRONGCHAR(const char c, char* _text, char* text_first, const char* srcfile, i32 line, const char* funcname){
|
||||||
char errBuf[68];
|
char errBuf[68];
|
||||||
for(uint8 n=0; n<sizeof(errBuf);n++)
|
for(u8 n=0; n<sizeof(errBuf);n++)
|
||||||
errBuf[n]='\0';
|
errBuf[n]='\0';
|
||||||
char* errText=_text-32;
|
char* errText=_text-32;
|
||||||
uint8 cplace=32;
|
u8 cplace=32;
|
||||||
if(errText<text_first) {
|
if(errText<text_first) {
|
||||||
cplace=_text-text_first;
|
cplace=_text-text_first;
|
||||||
errText=text_first;
|
errText=text_first;
|
||||||
}
|
}
|
||||||
uint8 i=0;
|
u8 i=0;
|
||||||
for(; i<cplace; i++){
|
for(; i<cplace; i++){
|
||||||
// writes 32 chars before the wrongchar
|
// writes 32 chars before the wrongchar
|
||||||
errBuf[i]=errText[i];
|
errBuf[i]=errText[i];
|
||||||
@@ -188,7 +188,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
|
|||||||
}
|
}
|
||||||
// UInt64
|
// UInt64
|
||||||
case 'u': {
|
case 'u': {
|
||||||
uint64 lu=0;
|
u64 lu=0;
|
||||||
char* _c=string_extract(str);
|
char* _c=string_extract(str);
|
||||||
if(sscanf(_c, IFWIN("%llu", "%lu"), &lu)!=1){
|
if(sscanf(_c, IFWIN("%llu", "%lu"), &lu)!=1){
|
||||||
char err[64];
|
char err[64];
|
||||||
@@ -204,7 +204,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
|
|||||||
// Int64
|
// Int64
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9': {
|
case '5': case '6': case '7': case '8': case '9': {
|
||||||
int64 li=0;
|
i64 li=0;
|
||||||
char* _c=string_extract(str);
|
char* _c=string_extract(str);
|
||||||
if(sscanf(_c, IFWIN("%lli", "%li"), &li)!=1){
|
if(sscanf(_c, IFWIN("%lli", "%li"), &li)!=1){
|
||||||
char err[64];
|
char err[64];
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ EXPORT void CALL kerep_DtsodV24_free(Hashtable* dtsod){
|
|||||||
DtsodV24_free(dtsod);
|
DtsodV24_free(dtsod);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void CALL kerep_DtsodV24_height(Hashtable* dtsod, uint16* heigth){
|
EXPORT void CALL kerep_DtsodV24_height(Hashtable* dtsod, u16* heigth){
|
||||||
*heigth=Hashtable_height(dtsod);
|
*heigth=Hashtable_height(dtsod);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void CALL kerep_DtsodV24_getrow(Hashtable* dtsod, uint16 h, Autoarr_KVPair** row){
|
EXPORT void CALL kerep_DtsodV24_getrow(Hashtable* dtsod, u16 h, Autoarr_KVPair** row){
|
||||||
*row=dtsod->rows[h];
|
*row=dtsod->rows[h];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,18 +4,18 @@
|
|||||||
|
|
||||||
typedef struct SerializeSharedData{
|
typedef struct SerializeSharedData{
|
||||||
StringBuilder* sh_builder;
|
StringBuilder* sh_builder;
|
||||||
uint8 sh_tabs;
|
u8 sh_tabs;
|
||||||
} SerializeSharedData;
|
} SerializeSharedData;
|
||||||
#define b shared->sh_builder
|
#define b shared->sh_builder
|
||||||
#define tabs shared->sh_tabs
|
#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)
|
#define addc(C) StringBuilder_append_char(b,C)
|
||||||
|
|
||||||
|
|
||||||
void __AppendTabs(SerializeSharedData* shared) {
|
void __AppendTabs(SerializeSharedData* shared) {
|
||||||
for (uint8 t = 0; t < tabs; t++)
|
for (u8 t = 0; t < tabs; t++)
|
||||||
addc( '\t');
|
addc( '\t');
|
||||||
};
|
};
|
||||||
#define AppendTabs() __AppendTabs(shared)
|
#define AppendTabs() __AppendTabs(shared)
|
||||||
@@ -23,15 +23,15 @@ void __AppendTabs(SerializeSharedData* shared) {
|
|||||||
Maybe __AppendValue(SerializeSharedData* shared, Unitype u);
|
Maybe __AppendValue(SerializeSharedData* shared, Unitype u);
|
||||||
#define AppendValue(UNI) __AppendValue(shared, UNI)
|
#define AppendValue(UNI) __AppendValue(shared, UNI)
|
||||||
Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
||||||
if(u.typeId==ktid_name(int64)){
|
if(u.typeId==ktid_name(i64)){
|
||||||
StringBuilder_append_int64(b,u.Int64);
|
StringBuilder_append_i64(b,u.Int64);
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktid_name(uint64)){
|
else if(u.typeId==ktid_name(u64)){
|
||||||
StringBuilder_append_uint64(b,u.UInt64);
|
StringBuilder_append_u64(b,u.UInt64);
|
||||||
addc('u');
|
addc('u');
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktid_name(float64)){
|
else if(u.typeId==ktid_name(f64)){
|
||||||
StringBuilder_append_float64(b,u.Float64);
|
StringBuilder_append_f64(b,u.Float64);
|
||||||
addc('f');
|
addc('f');
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktid_ptrName(char)){
|
else if(u.typeId==ktid_ptrName(char)){
|
||||||
@@ -102,7 +102,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
|||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
};
|
};
|
||||||
|
|
||||||
Maybe __serialize(StringBuilder* _b, uint8 _tabs, Hashtable* dtsod){
|
Maybe __serialize(StringBuilder* _b, u8 _tabs, Hashtable* dtsod){
|
||||||
SerializeSharedData _shared={
|
SerializeSharedData _shared={
|
||||||
.sh_builder=_b,
|
.sh_builder=_b,
|
||||||
.sh_tabs=_tabs
|
.sh_tabs=_tabs
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ bool dir_exists(const char* path){
|
|||||||
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is a directory
|
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is a directory
|
||||||
#else
|
#else
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
int rez=stat(path, &stats);
|
i32 rez=stat(path, &stats);
|
||||||
return (bool)(
|
return (bool)(
|
||||||
(rez!=-1) & // file exists
|
(rez!=-1) & // file exists
|
||||||
(S_ISDIR(stats.st_mode))); // file is a directory
|
(S_ISDIR(stats.st_mode))); // file is a directory
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ bool file_exists(const char* path){
|
|||||||
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is not directory
|
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is not directory
|
||||||
#else
|
#else
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
int rez=stat(path, &stats);
|
i32 rez=stat(path, &stats);
|
||||||
return (bool)(
|
return (bool)(
|
||||||
(rez!=-1) & // file exists
|
(rez!=-1) & // file exists
|
||||||
!(S_ISDIR(stats.st_mode))); // file is not directory
|
!(S_ISDIR(stats.st_mode))); // file is not directory
|
||||||
@@ -68,36 +68,36 @@ Maybe file_close(File* file){
|
|||||||
safethrow(ERR_IO,;);
|
safethrow(ERR_IO,;);
|
||||||
|
|
||||||
Maybe file_writeChar(File* file, char byte){
|
Maybe file_writeChar(File* file, char byte){
|
||||||
int rezult=fputc(byte, file);
|
i32 rezult=fputc(byte, file);
|
||||||
ioWriteCheck();
|
ioWriteCheck();
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_writeBuffer(File* file, char* buffer, uint64 length){
|
Maybe file_writeBuffer(File* file, char* buffer, u64 length){
|
||||||
int rezult=0;
|
i32 rezult=0;
|
||||||
for(uint64 i=0; i<length && !rezult; i++)
|
for(u64 i=0; i<length && !rezult; i++)
|
||||||
rezult=fputc(buffer[i], file);
|
rezult=fputc(buffer[i], file);
|
||||||
ioWriteCheck();
|
ioWriteCheck();
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_writeCptr(File* file, char* cptr){
|
Maybe file_writeCptr(File* file, char* cptr){
|
||||||
int rezult=fputs(cptr, file);
|
i32 rezult=fputs(cptr, file);
|
||||||
ioWriteCheck();
|
ioWriteCheck();
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Maybe file_readChar(File* file){
|
Maybe file_readChar(File* file){
|
||||||
int rezult=fgetc(file);
|
i32 rezult=fgetc(file);
|
||||||
if(feof(file)) safethrow(ERR_IO_EOF,;);
|
if(feof(file)) safethrow(ERR_IO_EOF,;);
|
||||||
if(ferror(file)) safethrow(ERR_IO,;);
|
if(ferror(file)) safethrow(ERR_IO,;);
|
||||||
return SUCCESS(UniUInt64(rezult));
|
return SUCCESS(UniUInt64(rezult));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_readBuffer(File* file, char* buffer, uint64 length){
|
Maybe file_readBuffer(File* file, char* buffer, u64 length){
|
||||||
int rezult=0;
|
i32 rezult=0;
|
||||||
uint64 i=0;
|
u64 i=0;
|
||||||
for(; i<length && rezult!=EOF; i++){
|
for(; i<length && rezult!=EOF; i++){
|
||||||
rezult=fgetc(file);
|
rezult=fgetc(file);
|
||||||
buffer[i]=(char)rezult;
|
buffer[i]=(char)rezult;
|
||||||
@@ -107,11 +107,11 @@ Maybe file_readBuffer(File* file, char* buffer, uint64 length){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Maybe file_readAll(File* file, char** allBytes){
|
Maybe file_readAll(File* file, char** allBytes){
|
||||||
int rezult=0;
|
i32 rezult=0;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
string bufStr={.ptr=buffer, .length=sizeof(buffer)};
|
string bufStr={.ptr=buffer, .length=sizeof(buffer)};
|
||||||
StringBuilder* sb=StringBuilder_create();
|
StringBuilder* sb=StringBuilder_create();
|
||||||
uint64 i=0;
|
u64 i=0;
|
||||||
while(true){
|
while(true){
|
||||||
rezult=fgetc(file);
|
rezult=fgetc(file);
|
||||||
if(rezult==EOF){
|
if(rezult==EOF){
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ Maybe file_writeChar(File* file, char byte);
|
|||||||
/// @param buffer bytes to write
|
/// @param buffer bytes to write
|
||||||
/// @param length buffer length
|
/// @param length buffer length
|
||||||
/// @return Maybe<void>
|
/// @return Maybe<void>
|
||||||
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
|
/// @brief writes all cstring array content to file
|
||||||
/// @param cptr zero-terminated cstring
|
/// @param cptr zero-terminated cstring
|
||||||
@@ -63,12 +63,12 @@ Maybe file_readChar(File* file);
|
|||||||
/// @brief reads byte array of specofied length
|
/// @brief reads byte array of specofied length
|
||||||
/// @param buffer buffer that will be filled with file bytes
|
/// @param buffer buffer that will be filled with file bytes
|
||||||
/// @param length buffer length
|
/// @param length buffer length
|
||||||
/// @return Maybe<uint64> total number of successfully read bytes (<=length)
|
/// @return Maybe<u64> total number of successfully read bytes (<=length)
|
||||||
Maybe file_readBuffer(File* file, char* buffer, uint64 length);
|
Maybe file_readBuffer(File* file, char* buffer, u64 length);
|
||||||
|
|
||||||
/// @brief reads all bytes from file
|
/// @brief reads all bytes from file
|
||||||
/// @param allBytes ptr to the file's content will be pushed there
|
/// @param allBytes ptr to the file's content will be pushed there
|
||||||
/// @return Maybe<uint64> total number of successfully read bytes
|
/// @return Maybe<u64> total number of successfully read bytes
|
||||||
Maybe file_readAll(File* file, char** allBytes);
|
Maybe file_readAll(File* file, char** allBytes);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
|
||||||
char* __path_concat(uint16 n, ...){
|
char* __path_concat(u16 n, ...){
|
||||||
char** parts=(char**)malloc(n*sizeof(char*));
|
char** parts=(char**)malloc(n*sizeof(char*));
|
||||||
uint32* lengths=malloc(n*sizeof(uint32));
|
u32* lengths=malloc(n*sizeof(u32));
|
||||||
uint32 totalLength=0;
|
u32 totalLength=0;
|
||||||
|
|
||||||
// reading args from va_list
|
// reading args from va_list
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, n);
|
va_start(vl, n);
|
||||||
for(uint16 i=0; i<n; i++){
|
for(u16 i=0; i<n; i++){
|
||||||
char* part=va_arg(vl,char*);
|
char* part=va_arg(vl,char*);
|
||||||
int16 length=cptr_length(part);
|
i16 length=cptr_length(part);
|
||||||
parts[i]=part;
|
parts[i]=part;
|
||||||
lengths[i]=length;
|
lengths[i]=length;
|
||||||
totalLength+=length;
|
totalLength+=length;
|
||||||
@@ -23,7 +23,7 @@ char* __path_concat(uint16 n, ...){
|
|||||||
totality[totalLength]=0;
|
totality[totalLength]=0;
|
||||||
|
|
||||||
// copying content of all strings to rezult
|
// copying content of all strings to rezult
|
||||||
uint16 k=0;
|
u16 k=0;
|
||||||
for(; k<n-1; k++){
|
for(; k<n-1; k++){
|
||||||
memcopy(parts[k], totality, lengths[k]);
|
memcopy(parts[k], totality, lengths[k]);
|
||||||
totality+=lengths[k];
|
totality+=lengths[k];
|
||||||
@@ -56,8 +56,8 @@ Maybe path_throwIfEscapes(const char* path){
|
|||||||
|
|
||||||
char* path_parentDir(char* dir){
|
char* path_parentDir(char* dir){
|
||||||
char* copy=cptr_copy(dir);
|
char* copy=cptr_copy(dir);
|
||||||
uint32 length=cptr_length(copy);
|
u32 length=cptr_length(copy);
|
||||||
int i=cptr_lastIndexOfChar(copy,path_sep);
|
i32 i=cptr_lastIndexOfChar(copy,path_sep);
|
||||||
if(i==length-1){
|
if(i==length-1){
|
||||||
copy[length-1]=0;
|
copy[length-1]=0;
|
||||||
i=cptr_lastIndexOfChar(copy,path_sep);
|
i=cptr_lastIndexOfChar(copy,path_sep);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ static const char path_sep='/';
|
|||||||
static const char path_notSep='\\';
|
static const char path_notSep='\\';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* __path_concat(uint16 n, ...);
|
char* __path_concat(u16 n, ...);
|
||||||
/// @brief merges path parts together and places <path_sep> between them
|
/// @brief merges path parts together and places <path_sep> between them
|
||||||
/// @return new cstr
|
/// @return new cstr
|
||||||
#define path_concat(PATH_PARTS...) __path_concat(count_args(PATH_PARTS), PATH_PARTS)
|
#define path_concat(PATH_PARTS...) __path_concat(count_args(PATH_PARTS), PATH_PARTS)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
uint32 hash_sdbm32(uint32 oldhash, void* buf, uint32 len){
|
u32 hash_sdbm32(u32 oldhash, void* buf, u32 len){
|
||||||
uint8* ubuf=(uint8*)buf;
|
u8* ubuf=(u8*)buf;
|
||||||
register uint32 hash=oldhash;
|
register u32 hash=oldhash;
|
||||||
for (; len ; len--, ubuf++)
|
for (; len ; len--, ubuf++)
|
||||||
hash=(hash<<6)+(hash<<16)-hash+*ubuf;
|
hash=(hash<<6)+(hash<<16)-hash+*ubuf;
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint32 crc_32_tab[]={
|
static const u32 crc_32_tab[]={
|
||||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
|
||||||
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||||
@@ -75,19 +75,19 @@ static const uint32 crc_32_tab[]={
|
|||||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32 hash_crc32(uint32 oldhash, void* buf, uint32 len){
|
u32 hash_crc32(u32 oldhash, void* buf, u32 len){
|
||||||
uint8* ubuf=(uint8*)buf;
|
u8* ubuf=(u8*)buf;
|
||||||
register uint32 crc=oldhash;
|
register u32 crc=oldhash;
|
||||||
for (; len; --len, ++ubuf)
|
for (; len; --len, ++ubuf)
|
||||||
crc=crc_32_tab[(crc^(*ubuf)) & 0xff] ^ (crc>>8);
|
crc=crc_32_tab[(crc^(*ubuf)) & 0xff] ^ (crc>>8);
|
||||||
return ~crc;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// bool hashf_crc32c(char *name, uint32 *crc, long *charcnt) {
|
// bool hashf_crc32c(char *name, u32 *crc, long *charcnt) {
|
||||||
// register FILE *fin;
|
// register FILE *fin;
|
||||||
// register uint32 oldcrc32;
|
// register u32 oldcrc32;
|
||||||
// register int c;
|
// register i32 c;
|
||||||
|
|
||||||
// oldcrc32 = 0xFFFFFFFF; *charcnt = 0;
|
// oldcrc32 = 0xFFFFFFFF; *charcnt = 0;
|
||||||
// if ((fin=fopen(name, "r"))==NULL) {
|
// if ((fin=fopen(name, "r"))==NULL) {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ extern "C" {
|
|||||||
#define hashb(FUNC, BUF, LEN) FUNC(0xFFFFFFFF, BUF, LEN)
|
#define hashb(FUNC, BUF, LEN) FUNC(0xFFFFFFFF, BUF, LEN)
|
||||||
#define hashs(FUNC, STR) FUNC(0xFFFFFFFF, STR, cptr_length(STR))
|
#define hashs(FUNC, STR) FUNC(0xFFFFFFFF, STR, cptr_length(STR))
|
||||||
|
|
||||||
uint32 hash_sdbm32(uint32 oldhash, void* buf, uint32 len);
|
u32 hash_sdbm32(u32 oldhash, void* buf, u32 len);
|
||||||
uint32 hash_crc32(uint32 oldhash, void* buf, uint32 len);
|
u32 hash_crc32(u32 oldhash, void* buf, u32 len);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
ktid_define(Hashtable);
|
ktid_define(Hashtable);
|
||||||
|
|
||||||
// amount of rows
|
// 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_MIN 0
|
||||||
#define HT_HEIN_MAX 6
|
#define HT_HEIN_MAX 6
|
||||||
|
|
||||||
@@ -14,14 +14,14 @@ Hashtable* Hashtable_create(){
|
|||||||
Hashtable* ht=malloc(sizeof(Hashtable));
|
Hashtable* ht=malloc(sizeof(Hashtable));
|
||||||
ht->hein=HT_HEIN_MIN;
|
ht->hein=HT_HEIN_MIN;
|
||||||
ht->rows=malloc(HT_HEIGHTS[HT_HEIN_MIN]*sizeof(Autoarr(KVPair)*));
|
ht->rows=malloc(HT_HEIGHTS[HT_HEIN_MIN]*sizeof(Autoarr(KVPair)*));
|
||||||
for(uint16 i=0;i<HT_HEIGHTS[HT_HEIN_MIN];i++)
|
for(u16 i=0;i<HT_HEIGHTS[HT_HEIN_MIN];i++)
|
||||||
ht->rows[i]=Autoarr_create(KVPair,ARR_BC,ARR_BL);
|
ht->rows[i]=Autoarr_create(KVPair,ARR_BC,ARR_BL);
|
||||||
return ht;
|
return ht;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __Hashtable_free(void* _ht){
|
void __Hashtable_free(void* _ht){
|
||||||
Hashtable* ht=_ht;
|
Hashtable* ht=_ht;
|
||||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein];i++)
|
for(u16 i=0;i<HT_HEIGHTS[ht->hein];i++)
|
||||||
Autoarr_free(ht->rows[i], true);
|
Autoarr_free(ht->rows[i], true);
|
||||||
free(ht->rows);
|
free(ht->rows);
|
||||||
}
|
}
|
||||||
@@ -30,22 +30,22 @@ void Hashtable_free(Hashtable* ht){
|
|||||||
free(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){
|
void Hashtable_expand(Hashtable* ht){
|
||||||
if(ht->hein>=HT_HEIN_MAX) throw(ERR_MAXLENGTH);
|
if(ht->hein>=HT_HEIN_MAX) throw(ERR_MAXLENGTH);
|
||||||
|
|
||||||
Autoarr(KVPair)** newrows=malloc(HT_HEIGHTS[++ht->hein]*sizeof(Autoarr(KVPair)*));
|
Autoarr(KVPair)** newrows=malloc(HT_HEIGHTS[++ht->hein]*sizeof(Autoarr(KVPair)*));
|
||||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein];i++)
|
for(u16 i=0;i<HT_HEIGHTS[ht->hein];i++)
|
||||||
newrows[i]=Autoarr_create(KVPair,ARR_BC,ARR_BL);
|
newrows[i]=Autoarr_create(KVPair,ARR_BC,ARR_BL);
|
||||||
|
|
||||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein-1];i++){
|
for(u16 i=0;i<HT_HEIGHTS[ht->hein-1];i++){
|
||||||
Autoarr(KVPair)* ar=ht->rows[i];
|
Autoarr(KVPair)* ar=ht->rows[i];
|
||||||
uint32 arlen=Autoarr_length(ar);
|
u32 arlen=Autoarr_length(ar);
|
||||||
for(uint32 k=0;k<arlen;k++){
|
for(u32 k=0;k<arlen;k++){
|
||||||
KVPair p=Autoarr_get(ar,k);
|
KVPair p=Autoarr_get(ar,k);
|
||||||
uint16 newrown=hashs(hash_sdbm32, p.key)%HT_HEIGHTS[ht->hein];
|
u16 newrown=hashs(hash_sdbm32, p.key)%HT_HEIGHTS[ht->hein];
|
||||||
Autoarr(KVPair)* newar=newrows[newrown];
|
Autoarr(KVPair)* newar=newrows[newrown];
|
||||||
Autoarr_add(newar,p);
|
Autoarr_add(newar,p);
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ void Hashtable_expand(Hashtable* ht){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Autoarr(KVPair)* getrow(Hashtable* ht, char* key, bool can_expand){
|
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]];
|
Autoarr(KVPair)* ar=ht->rows[hash%HT_HEIGHTS[ht->hein]];
|
||||||
if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar))
|
if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar))
|
||||||
Hashtable_expand(ht);
|
Hashtable_expand(ht);
|
||||||
@@ -74,8 +74,8 @@ void Hashtable_add(Hashtable* ht, char* key, Unitype u){
|
|||||||
// returns null or pointer to value in hashtable
|
// returns null or pointer to value in hashtable
|
||||||
Unitype* Hashtable_getptr(Hashtable* ht, char* key){
|
Unitype* Hashtable_getptr(Hashtable* ht, char* key){
|
||||||
Autoarr(KVPair)* ar=getrow(ht,key,false);
|
Autoarr(KVPair)* ar=getrow(ht,key,false);
|
||||||
uint32 arlen=Autoarr_length(ar);
|
u32 arlen=Autoarr_length(ar);
|
||||||
for(uint32 i=0;i<arlen;i++){
|
for(u32 i=0;i<arlen;i++){
|
||||||
KVPair* p=Autoarr_getptr(ar,i);
|
KVPair* p=Autoarr_getptr(ar,i);
|
||||||
if(cptr_compare(key,p->key)) return &p->value;
|
if(cptr_compare(key,p->key)) return &p->value;
|
||||||
}
|
}
|
||||||
@@ -84,8 +84,8 @@ Unitype* Hashtable_getptr(Hashtable* ht, char* key){
|
|||||||
|
|
||||||
Unitype Hashtable_get(Hashtable* ht, char* key){
|
Unitype Hashtable_get(Hashtable* ht, char* key){
|
||||||
Autoarr(KVPair)* ar=getrow(ht,key,false);
|
Autoarr(KVPair)* ar=getrow(ht,key,false);
|
||||||
uint32 arlen=Autoarr_length(ar);
|
u32 arlen=Autoarr_length(ar);
|
||||||
for(uint32 i=0;i<arlen;i++){
|
for(u32 i=0;i<arlen;i++){
|
||||||
KVPair p=Autoarr_get(ar,i);
|
KVPair p=Autoarr_get(ar,i);
|
||||||
if(cptr_compare(key,p.key)) return p.value;
|
if(cptr_compare(key,p.key)) return p.value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ extern "C" {
|
|||||||
#include "KeyValuePair.h"
|
#include "KeyValuePair.h"
|
||||||
|
|
||||||
typedef struct Hashtable{
|
typedef struct Hashtable{
|
||||||
uint8 hein; // height=HT_HEIGHTS[hein]
|
u8 hein; // height=HT_HEIGHTS[hein]
|
||||||
Autoarr(KVPair)** rows; // Autoarr[height]
|
Autoarr(KVPair)** rows; // Autoarr[height]
|
||||||
} Hashtable;
|
} Hashtable;
|
||||||
ktid_declare(Hashtable);
|
ktid_declare(Hashtable);
|
||||||
@@ -18,7 +18,7 @@ void Hashtable_free(Hashtable* ht);
|
|||||||
void __Hashtable_free(void* ht);
|
void __Hashtable_free(void* ht);
|
||||||
|
|
||||||
// amount of rows
|
// amount of rows
|
||||||
uint16 Hashtable_height(Hashtable* ht);
|
u16 Hashtable_height(Hashtable* ht);
|
||||||
|
|
||||||
// don't add pairs with the same keys,
|
// don't add pairs with the same keys,
|
||||||
// or something weird will happen
|
// or something weird will happen
|
||||||
@@ -34,8 +34,8 @@ Unitype Hashtable_get(Hashtable* ht, char* key);
|
|||||||
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output);
|
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output);
|
||||||
|
|
||||||
#define Hashtable_foreach(HT, EL, codeblock)({\
|
#define Hashtable_foreach(HT, EL, codeblock)({\
|
||||||
uint16 hmax=Hashtable_height(HT);\
|
u16 hmax=Hashtable_height(HT);\
|
||||||
for(uint16 h=0; h<hmax; h++){\
|
for(u16 h=0; h<hmax; h++){\
|
||||||
Autoarr(KVPair)* AR=HT->rows[h];\
|
Autoarr(KVPair)* AR=HT->rows[h];\
|
||||||
Autoarr_foreach(AR, EL, codeblock);\
|
Autoarr_foreach(AR, EL, codeblock);\
|
||||||
}\
|
}\
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ void __STNode_free(void* _node){
|
|||||||
STNode* node=_node;
|
STNode* node=_node;
|
||||||
if (!node) throw(ERR_NULLPTR);
|
if (!node) throw(ERR_NULLPTR);
|
||||||
if(node->branches){
|
if(node->branches){
|
||||||
for(uint8 n32 = 0;n32<8;n32++){
|
for(u8 n32 = 0;n32<8;n32++){
|
||||||
STNode*** ptrn32=(STNode***)node->branches[n32];
|
STNode*** ptrn32=(STNode***)node->branches[n32];
|
||||||
if(ptrn32){
|
if(ptrn32){
|
||||||
for(uint8 n4 = 0;n4<8;n4++){
|
for(u8 n4 = 0;n4<8;n4++){
|
||||||
STNode** ptrn4=ptrn32[n4];
|
STNode** ptrn4=ptrn32[n4];
|
||||||
if (ptrn4){
|
if (ptrn4){
|
||||||
for(uint8 rem=0;rem<4;rem++){
|
for(u8 rem=0;rem<4;rem++){
|
||||||
STNode* ptrrem=ptrn4[rem];
|
STNode* ptrrem=ptrn4[rem];
|
||||||
if(ptrrem)
|
if(ptrrem)
|
||||||
STNode_free(ptrrem);
|
STNode_free(ptrrem);
|
||||||
@@ -41,9 +41,9 @@ void STNode_free(STNode* node){
|
|||||||
free(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){
|
return (indexes3){
|
||||||
.n32=i/32,
|
.n32=i/32,
|
||||||
.n4=i%32/4,
|
.n4=i%32/4,
|
||||||
@@ -60,20 +60,20 @@ void ST_pushString(STNode* node_first, string key, Unitype value){
|
|||||||
if (!node_first) throw(ERR_NULLPTR);
|
if (!node_first) throw(ERR_NULLPTR);
|
||||||
STNode* node_last=node_first;
|
STNode* node_last=node_first;
|
||||||
while(key.length--){
|
while(key.length--){
|
||||||
indexes3 i3=splitindex((uint8)*key.ptr);
|
indexes3 i3=splitindex((u8)*key.ptr);
|
||||||
if(!node_last->branches){
|
if(!node_last->branches){
|
||||||
node_last->branches=(STNode****)malloc(8*sizeof(STNode***));
|
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;
|
node_last->branches[i]=(STNode***)NULL;
|
||||||
}
|
}
|
||||||
if(!node_last->branches[i3.n32]){
|
if(!node_last->branches[i3.n32]){
|
||||||
node_last->branches[i3.n32]=(STNode***)malloc(8*sizeof(STNode**));
|
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;
|
node_last->branches[i3.n32][i]=(STNode**)NULL;
|
||||||
}
|
}
|
||||||
if(!node_last->branches[i3.n32][i3.n4]){
|
if(!node_last->branches[i3.n32][i3.n4]){
|
||||||
node_last->branches[i3.n32][i3.n4]=(STNode**)malloc(4*sizeof(STNode*));
|
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;
|
node_last->branches[i3.n32][i3.n4][i]=(STNode*)NULL;
|
||||||
}
|
}
|
||||||
if(!node_last->branches[i3.n32][i3.n4][i3.rem])
|
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);
|
if (!node_first) throw(ERR_NULLPTR);
|
||||||
STNode* node_last=node_first;
|
STNode* node_last=node_first;
|
||||||
while (key.length--){
|
while (key.length--){
|
||||||
indexes3 i3=splitindex((uint8)*key.ptr);
|
indexes3 i3=splitindex((u8)*key.ptr);
|
||||||
if(!node_last->branches) return UniNull;
|
if(!node_last->branches) return UniNull;
|
||||||
STNode*** ptrn32=(STNode***)node_last->branches[i3.n32];
|
STNode*** ptrn32=(STNode***)node_last->branches[i3.n32];
|
||||||
if(!ptrn32) return UniNull;
|
if(!ptrn32) return UniNull;
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ ktid_define(StringBuilder);
|
|||||||
void complete_buf(StringBuilder* b){
|
void complete_buf(StringBuilder* b){
|
||||||
if(!b->compl_bufs)
|
if(!b->compl_bufs)
|
||||||
b->compl_bufs=Autoarr_create(string,BL_C,BL_L);
|
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;
|
if(!len) return;
|
||||||
string str={.length=len, .ptr=malloc(len)};
|
string str={.length=len, .ptr=malloc(len)};
|
||||||
uint32 i=0;
|
u32 i=0;
|
||||||
Autoarr_foreach(b->curr_buf, c, ({
|
Autoarr_foreach(b->curr_buf, c, ({
|
||||||
str.ptr[i++]=c;
|
str.ptr[i++]=c;
|
||||||
}));
|
}));
|
||||||
Autoarr_add(b->compl_bufs,str);
|
Autoarr_add(b->compl_bufs,str);
|
||||||
Autoarr_free(b->curr_buf, true);
|
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){
|
void try_complete_buf(StringBuilder* b){
|
||||||
@@ -32,7 +32,7 @@ void try_complete_buf(StringBuilder* b){
|
|||||||
StringBuilder* StringBuilder_create(){
|
StringBuilder* StringBuilder_create(){
|
||||||
StringBuilder* b=malloc(sizeof(StringBuilder));
|
StringBuilder* b=malloc(sizeof(StringBuilder));
|
||||||
b->compl_bufs=NULL;
|
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;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,15 +48,15 @@ void StringBuilder_free(StringBuilder* b){
|
|||||||
|
|
||||||
string StringBuilder_build(StringBuilder* b){
|
string StringBuilder_build(StringBuilder* b){
|
||||||
complete_buf(b);
|
complete_buf(b);
|
||||||
uint32 len=0;
|
u32 len=0;
|
||||||
Autoarr_foreach(b->compl_bufs, cs, ({
|
Autoarr_foreach(b->compl_bufs, cs, ({
|
||||||
len+=cs.length;
|
len+=cs.length;
|
||||||
}));
|
}));
|
||||||
string str= { .length=len, .ptr=malloc(len+1) };
|
string str= { .length=len, .ptr=malloc(len+1) };
|
||||||
str.ptr[len]='\0';
|
str.ptr[len]='\0';
|
||||||
uint32 i=0;
|
u32 i=0;
|
||||||
Autoarr_foreach(b->compl_bufs, cs, ({
|
Autoarr_foreach(b->compl_bufs, cs, ({
|
||||||
for(uint32 n=0;n<cs.length;n++)
|
for(u32 n=0;n<cs.length;n++)
|
||||||
str.ptr[i++]=cs.ptr[n];
|
str.ptr[i++]=cs.ptr[n];
|
||||||
free(cs.ptr);
|
free(cs.ptr);
|
||||||
}));
|
}));
|
||||||
@@ -96,13 +96,13 @@ void StringBuilder_append_cptr(StringBuilder* b, char* s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void curr_buf_add_string(StringBuilder* b, string s){
|
void curr_buf_add_string(StringBuilder* b, string s){
|
||||||
for(uint32 i=0; i<s.length; i++)
|
for(u32 i=0; i<s.length; i++)
|
||||||
Autoarr_add(b->curr_buf,s.ptr[i]);
|
Autoarr_add(b->curr_buf,s.ptr[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder_append_int64(StringBuilder* b, int64 a){
|
void StringBuilder_append_i64(StringBuilder* b, i64 a){
|
||||||
try_complete_buf(b);
|
try_complete_buf(b);
|
||||||
uint8 i=0;
|
u8 i=0;
|
||||||
if(a==0){
|
if(a==0){
|
||||||
Autoarr_add(b->curr_buf,'0');
|
Autoarr_add(b->curr_buf,'0');
|
||||||
return;
|
return;
|
||||||
@@ -121,9 +121,9 @@ void StringBuilder_append_int64(StringBuilder* b, int64 a){
|
|||||||
free(rev.ptr);
|
free(rev.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
|
void StringBuilder_append_u64(StringBuilder* b, u64 a){
|
||||||
try_complete_buf(b);
|
try_complete_buf(b);
|
||||||
uint8 i=0;
|
u8 i=0;
|
||||||
if(a==0){
|
if(a==0){
|
||||||
Autoarr_add(b->curr_buf,'0');
|
Autoarr_add(b->curr_buf,'0');
|
||||||
return;
|
return;
|
||||||
@@ -138,7 +138,7 @@ void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
|
|||||||
free(rev.ptr);
|
free(rev.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder_append_float64(StringBuilder* b, double a){
|
void StringBuilder_append_f64(StringBuilder* b, f64 a){
|
||||||
try_complete_buf(b);
|
try_complete_buf(b);
|
||||||
char buf[32];
|
char buf[32];
|
||||||
IFMSC(
|
IFMSC(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Autoarr_declare(string)
|
|||||||
|
|
||||||
typedef struct StringBuilder{
|
typedef struct StringBuilder{
|
||||||
Autoarr(string)* compl_bufs;
|
Autoarr(string)* compl_bufs;
|
||||||
Autoarr(int8)* curr_buf;
|
Autoarr(i8)* curr_buf;
|
||||||
} StringBuilder;
|
} StringBuilder;
|
||||||
ktid_declare(StringBuilder);
|
ktid_declare(StringBuilder);
|
||||||
|
|
||||||
@@ -28,9 +28,9 @@ void StringBuilder_rmchar(StringBuilder* b);
|
|||||||
void StringBuilder_append_char(StringBuilder* b, char c);
|
void StringBuilder_append_char(StringBuilder* b, char c);
|
||||||
void StringBuilder_append_cptr(StringBuilder* b, char* s);
|
void StringBuilder_append_cptr(StringBuilder* b, char* s);
|
||||||
void StringBuilder_append_string(StringBuilder* b, string s);
|
void StringBuilder_append_string(StringBuilder* b, string s);
|
||||||
void StringBuilder_append_int64(StringBuilder* b, int64 a);
|
void StringBuilder_append_i64(StringBuilder* b, i64 a);
|
||||||
void StringBuilder_append_uint64(StringBuilder* b, uint64 a);
|
void StringBuilder_append_u64(StringBuilder* b, u64 a);
|
||||||
void StringBuilder_append_float64(StringBuilder* b, double a);
|
void StringBuilder_append_f64(StringBuilder* b, f64 a);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ string string_copy(string src){
|
|||||||
string nstr;
|
string nstr;
|
||||||
nstr.length=src.length;
|
nstr.length=src.length;
|
||||||
nstr.ptr=malloc(nstr.length);
|
nstr.ptr=malloc(nstr.length);
|
||||||
for(uint32 i=0;i<nstr.length;i++)
|
for(u32 i=0;i<nstr.length;i++)
|
||||||
nstr.ptr[i]=src.ptr[i];
|
nstr.ptr[i]=src.ptr[i];
|
||||||
return nstr;
|
return nstr;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ bool string_compare(string str0, string str1){
|
|||||||
string string_reverse(string s){
|
string string_reverse(string s){
|
||||||
if(s.length==0) return s;
|
if(s.length==0) return s;
|
||||||
string r={malloc(s.length), s.length};
|
string r={malloc(s.length), s.length};
|
||||||
for(uint32 i=0; i<s.length; i++)
|
for(u32 i=0; i<s.length; i++)
|
||||||
r.ptr[i]=s.ptr[s.length-i-1];
|
r.ptr[i]=s.ptr[s.length-i-1];
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ extern "C" {
|
|||||||
// doesn't store '\0' at the end
|
// doesn't store '\0' at the end
|
||||||
typedef struct string{
|
typedef struct string{
|
||||||
char* ptr; // char pointer
|
char* ptr; // char pointer
|
||||||
uint64 length; // amount of chars in ptr value
|
u64 length; // amount of chars in ptr value
|
||||||
} string;
|
} string;
|
||||||
ktid_declare(string);
|
ktid_declare(string);
|
||||||
Array_declare(string);
|
Array_declare(string);
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
|
||||||
// returns length of char buffer (without \0)
|
// returns length of char buffer (without \0)
|
||||||
uint32 cptr_length(char* str){
|
u32 cptr_length(char* str){
|
||||||
uint32 len=0;
|
u32 len=0;
|
||||||
while(*(str++)) len++;
|
while(*(str++)) len++;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocates new char[] and copies src there
|
// allocates new char[] and copies src there
|
||||||
char* cptr_copy(char* src){
|
char* cptr_copy(char* src){
|
||||||
uint32 len=cptr_length(src)+1;
|
u32 len=cptr_length(src)+1;
|
||||||
char* dst=malloc(len);
|
char* dst=malloc(len);
|
||||||
while(len--!=0)
|
while(len--!=0)
|
||||||
dst[len]=src[len];
|
dst[len]=src[len];
|
||||||
@@ -27,7 +27,7 @@ bool cptr_compare(char* key0, char* key1){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// multiplies char n times
|
// multiplies char n times
|
||||||
char* char_multiply(char c, uint32 n){
|
char* char_multiply(char c, u32 n){
|
||||||
char* rez=malloc(n+1);
|
char* rez=malloc(n+1);
|
||||||
rez[n]=0;
|
rez[n]=0;
|
||||||
while(n--!=0)
|
while(n--!=0)
|
||||||
@@ -48,9 +48,9 @@ bool cptr_endsWith(char* ptr, char* fragment){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 cptr_indexOf(char* ptr, char* fragment){
|
u32 cptr_indexOf(char* ptr, char* fragment){
|
||||||
char sc=*ptr;
|
char sc=*ptr;
|
||||||
for(int si=0, fi=0; sc!=0; si++){
|
for(i32 si=0, fi=0; sc!=0; si++){
|
||||||
sc=ptr[si];
|
sc=ptr[si];
|
||||||
if(sc==fragment[fi]){
|
if(sc==fragment[fi]){
|
||||||
fi++;
|
fi++;
|
||||||
@@ -61,9 +61,9 @@ uint32 cptr_indexOf(char* ptr, char* fragment){
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uint32 cptr_indexOfChar(char* ptr, char fragment){
|
u32 cptr_indexOfChar(char* ptr, char fragment){
|
||||||
char sc=*ptr;
|
char sc=*ptr;
|
||||||
for(int si=0; sc!=0; si++){
|
for(i32 si=0; sc!=0; si++){
|
||||||
sc=ptr[si];
|
sc=ptr[si];
|
||||||
if(sc==fragment){
|
if(sc==fragment){
|
||||||
return si;
|
return si;
|
||||||
@@ -71,10 +71,10 @@ uint32 cptr_indexOfChar(char* ptr, char fragment){
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uint32 cptr_lastIndexOf(char* ptr, char* fragment){
|
u32 cptr_lastIndexOf(char* ptr, char* fragment){
|
||||||
char sc=*ptr;
|
char sc=*ptr;
|
||||||
int fi_last=cptr_length(fragment)-1;
|
i32 fi_last=cptr_length(fragment)-1;
|
||||||
for(int si=cptr_length(ptr)-1, fi=fi_last; si>=0; si--){
|
for(i32 si=cptr_length(ptr)-1, fi=fi_last; si>=0; si--){
|
||||||
sc=ptr[si];
|
sc=ptr[si];
|
||||||
if(sc==fragment[fi]){
|
if(sc==fragment[fi]){
|
||||||
if(fi==0)
|
if(fi==0)
|
||||||
@@ -85,9 +85,9 @@ uint32 cptr_lastIndexOf(char* ptr, char* fragment){
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uint32 cptr_lastIndexOfChar(char* ptr, char fragment){
|
u32 cptr_lastIndexOfChar(char* ptr, char fragment){
|
||||||
char sc=*ptr;
|
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];
|
sc=ptr[si];
|
||||||
if(sc==fragment){
|
if(sc==fragment){
|
||||||
return si;
|
return si;
|
||||||
@@ -96,24 +96,24 @@ uint32 cptr_lastIndexOfChar(char* ptr, char fragment){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memcopy(void* from, void* to, uint32 size){
|
void memcopy(void* from, void* to, u32 size){
|
||||||
if(from==NULL || to==NULL)
|
if(from==NULL || to==NULL)
|
||||||
throw(ERR_NULLPTR);
|
throw(ERR_NULLPTR);
|
||||||
for(uint32 i=0; i<size; i++)
|
for(u32 i=0; i<size; i++)
|
||||||
((char*)to)[i]=((char*)from)[i];
|
((char*)to)[i]=((char*)from)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
char* __cptr_concat(uint16 n, ...){
|
char* __cptr_concat(u16 n, ...){
|
||||||
char** strs=(char**)malloc(n*sizeof(char*));
|
char** strs=(char**)malloc(n*sizeof(char*));
|
||||||
uint32* lengths=malloc(n*sizeof(uint32));
|
u32* lengths=malloc(n*sizeof(u32));
|
||||||
uint32 totalLength=0;
|
u32 totalLength=0;
|
||||||
|
|
||||||
// reading args from va_list
|
// reading args from va_list
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, n);
|
va_start(vl, n);
|
||||||
for(uint16 i=0; i<n; i++){
|
for(u16 i=0; i<n; i++){
|
||||||
char* str=va_arg(vl,char*);
|
char* str=va_arg(vl,char*);
|
||||||
int16 length=cptr_length(str);
|
i16 length=cptr_length(str);
|
||||||
strs[i]=str;
|
strs[i]=str;
|
||||||
lengths[i]=length;
|
lengths[i]=length;
|
||||||
totalLength+=length;
|
totalLength+=length;
|
||||||
@@ -126,7 +126,7 @@ char* __cptr_concat(uint16 n, ...){
|
|||||||
totality[totalLength]=0;
|
totality[totalLength]=0;
|
||||||
|
|
||||||
// copying content of all strings to rezult
|
// copying content of all strings to rezult
|
||||||
for(uint16 k=0; k<n; k++){
|
for(u16 k=0; k<n; k++){
|
||||||
memcopy(strs[k], totality, lengths[k]);
|
memcopy(strs[k], totality, lengths[k]);
|
||||||
totality+=lengths[k];
|
totality+=lengths[k];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ extern "C" {
|
|||||||
#include "std.h"
|
#include "std.h"
|
||||||
|
|
||||||
// returns length of char buffer (without \0)
|
// returns length of char buffer (without \0)
|
||||||
uint32 cptr_length(char* str);
|
u32 cptr_length(char* str);
|
||||||
|
|
||||||
// allocates new char[] and copies src there
|
// allocates new char[] and copies src there
|
||||||
char* cptr_copy(char* src);
|
char* cptr_copy(char* src);
|
||||||
@@ -16,7 +16,7 @@ char* cptr_copy(char* src);
|
|||||||
bool cptr_compare(char* key0, char* key1);
|
bool cptr_compare(char* key0, char* key1);
|
||||||
|
|
||||||
// multiplies char n times
|
// multiplies char n times
|
||||||
char* char_multiply(char c, uint32 n);
|
char* char_multiply(char c, u32 n);
|
||||||
|
|
||||||
bool cptr_startsWith(char* ptr, char* fragment);
|
bool cptr_startsWith(char* ptr, char* fragment);
|
||||||
|
|
||||||
@@ -24,16 +24,16 @@ bool cptr_endsWith(char* ptr, char* fragment);
|
|||||||
|
|
||||||
/// @brief search for <fragment> in <ptr>
|
/// @brief search for <fragment> in <ptr>
|
||||||
/// @return index of first <fragment> inclusion or -1 if not found
|
/// @return index of first <fragment> inclusion or -1 if not found
|
||||||
uint32 cptr_indexOf(char* ptr, char* fragment);
|
u32 cptr_indexOf(char* ptr, char* fragment);
|
||||||
/// @brief search for <fragment> in <ptr>
|
/// @brief search for <fragment> in <ptr>
|
||||||
/// @return index of first <fragment> inclusion or -1 if not found
|
/// @return index of first <fragment> inclusion or -1 if not found
|
||||||
uint32 cptr_indexOfChar(char* ptr, char fragment);
|
u32 cptr_indexOfChar(char* ptr, char fragment);
|
||||||
/// @brief search for <fragment> in <ptr>
|
/// @brief search for <fragment> in <ptr>
|
||||||
/// @return index of last <fragment> inclusion or -1 if not found
|
/// @return index of last <fragment> inclusion or -1 if not found
|
||||||
uint32 cptr_lastIndexOf(char* ptr, char* fragment);
|
u32 cptr_lastIndexOf(char* ptr, char* fragment);
|
||||||
/// @brief search for <fragment> in <ptr>
|
/// @brief search for <fragment> in <ptr>
|
||||||
/// @return index of last <fragment> inclusion or -1 if not found
|
/// @return index of last <fragment> 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){
|
static inline bool cptr_contains(char* ptr, char* fragment){
|
||||||
// if(cptr_indexOf(ptr, fragment)==-1)
|
// 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;
|
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)
|
#define cptr_concat(STR...) __cptr_concat(count_args(STR), STR)
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
static const union
|
static const union
|
||||||
{
|
{
|
||||||
uint16 number;
|
u16 number;
|
||||||
Endian bytes[2];
|
Endian bytes[2];
|
||||||
} _endian_union={ .number=0x0102 };
|
} _endian_union={ .number=0x0102 };
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ char* errname(ErrorId err){
|
|||||||
|
|
||||||
#define ERRMSG_MAXLENGTH 1024
|
#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;
|
size_t bufsize=ERRMSG_MAXLENGTH;
|
||||||
char* rezult=malloc(bufsize);
|
char* rezult=malloc(bufsize);
|
||||||
IFMSC(
|
IFMSC(
|
||||||
@@ -33,7 +33,7 @@ char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char*
|
|||||||
return rezult;
|
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;
|
size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH;
|
||||||
char* rezult=malloc(bufsize);
|
char* rezult=malloc(bufsize);
|
||||||
IFMSC(
|
IFMSC(
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ PACK_ENUM(ErrorId,
|
|||||||
|
|
||||||
char* errname(ErrorId err);
|
char* errname(ErrorId err);
|
||||||
|
|
||||||
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);
|
||||||
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);
|
||||||
|
|
||||||
typedef struct Maybe{
|
typedef struct Maybe{
|
||||||
Unitype value;
|
Unitype value;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define __optime_print(opname, t)\
|
#define __optime_print(opname, t)\
|
||||||
char tnames[3][3]={"s\0","ms","us"};\
|
char tnames[3][3]={"s\0","ms","us"};\
|
||||||
int tni=0;\
|
i32 tni=0;\
|
||||||
if(t>1000000){\
|
if(t>1000000){\
|
||||||
t/=1000000;\
|
t/=1000000;\
|
||||||
tni=0;\
|
tni=0;\
|
||||||
@@ -17,25 +17,25 @@
|
|||||||
|
|
||||||
#ifdef CLOCK_REALTIME
|
#ifdef CLOCK_REALTIME
|
||||||
/// executes codeblock and prints execution time
|
/// 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
|
/// uses non-standard high-precision clock
|
||||||
#define optime(opname,repeats,codeblock) ({\
|
#define optime(opname,repeats,codeblock) ({\
|
||||||
struct timespec start, stop;\
|
struct timespec start, stop;\
|
||||||
clock_gettime(CLOCK_REALTIME, &start);\
|
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);\
|
(codeblock);\
|
||||||
clock_gettime(CLOCK_REALTIME, &stop);\
|
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)\
|
__optime_print(opname,t)\
|
||||||
})
|
})
|
||||||
#else
|
#else
|
||||||
/// uses standard low precision clock
|
/// uses standard low precision clock
|
||||||
#define optime(opname,repeats,codeblock) ({\
|
#define optime(opname,repeats,codeblock) ({\
|
||||||
clock_t start=clock();\
|
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);\
|
(codeblock);\
|
||||||
clock_t stop=clock();\
|
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)\
|
__optime_print(opname,t)\
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,22 +12,23 @@ extern "C" {
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
typedef int8_t int8;
|
typedef int8_t i8;
|
||||||
typedef uint8_t uint8;
|
typedef uint8_t u8;
|
||||||
typedef int16_t int16;
|
typedef int16_t i16;
|
||||||
typedef uint16_t uint16;
|
typedef uint16_t u16;
|
||||||
typedef int32_t int32;
|
typedef int32_t i32;
|
||||||
typedef uint32_t uint32;
|
typedef uint32_t u32;
|
||||||
typedef int64_t int64;
|
typedef int64_t i64;
|
||||||
typedef uint64_t uint64;
|
typedef uint64_t u64;
|
||||||
typedef float float32;
|
typedef float f32;
|
||||||
typedef double float64;
|
typedef double f64;
|
||||||
|
|
||||||
// Usually bool from stdbool.h is defined as macro,
|
// Usually bool from stdbool.h is defined as macro,
|
||||||
// so in other macros like ktid_##TYPE it will be replaced by _Bool.
|
// so in other macros like ktid_##TYPE it will be replaced by _Bool.
|
||||||
// ktid__Bool will be created instead of ktid_bool
|
// ktid__Bool will be created instead of ktid_bool
|
||||||
// In C++ bool is a keyword, so there is no need to redefine it.
|
// In C++ bool is a keyword, so there is no need to redefine it.
|
||||||
#if !__cplusplus
|
#if !__cplusplus
|
||||||
typedef uint8 bool;
|
typedef u8 bool;
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "../base.h"
|
#include "../base.h"
|
||||||
#include "../../kprint/kprint_format.h"
|
#include "../../kprint/kprint_format.h"
|
||||||
|
|
||||||
char* __toString_char(void* c, uint32 fmt) {
|
char* __toString_char(void* c, u32 fmt) {
|
||||||
//*c=char
|
//*c=char
|
||||||
if(kp_fmt_dataFormat(fmt)==kp_c){
|
if(kp_fmt_dataFormat(fmt)==kp_c){
|
||||||
char* cc=malloc(2);
|
char* cc=malloc(2);
|
||||||
@@ -17,9 +17,9 @@ char* __toString_char(void* c, uint32 fmt) {
|
|||||||
else throw(ERR_FORMAT);
|
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" };
|
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);
|
char* rez=malloc(6);
|
||||||
rez[0]=_strbool[strind][0];
|
rez[0]=_strbool[strind][0];
|
||||||
rez[1]=_strbool[strind][1];
|
rez[1]=_strbool[strind][1];
|
||||||
@@ -30,10 +30,10 @@ char* __toString_bool(void* c, uint32 fmt) {
|
|||||||
return rez;
|
return rez;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_int(int64 n){
|
char* toString_i64(i64 n){
|
||||||
int64 d=n<0 ? -1*n : n;
|
i64 d=n<0 ? -1*n : n;
|
||||||
char str[32];
|
char str[32];
|
||||||
uint8 i=sizeof(str);
|
u8 i=sizeof(str);
|
||||||
str[--i]=0;
|
str[--i]=0;
|
||||||
if(d==0)
|
if(d==0)
|
||||||
str[--i]='0';
|
str[--i]='0';
|
||||||
@@ -46,9 +46,9 @@ char* toString_int(int64 n){
|
|||||||
return cptr_copy((char*)str+i);
|
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];
|
char str[32];
|
||||||
uint8 i=sizeof(str);
|
u8 i=sizeof(str);
|
||||||
str[--i]=0;
|
str[--i]=0;
|
||||||
if(withPostfix)
|
if(withPostfix)
|
||||||
str[--i]= uppercase ? 'U' : 'u';
|
str[--i]= uppercase ? 'U' : 'u';
|
||||||
@@ -67,7 +67,7 @@ char* toString_uint(uint64 n, bool withPostfix, bool uppercase){
|
|||||||
throw("too big precision");\
|
throw("too big precision");\
|
||||||
if(precision==0)\
|
if(precision==0)\
|
||||||
precision=toString_float_default_precision;\
|
precision=toString_float_default_precision;\
|
||||||
int cn=IFMSC(\
|
i32 cn=IFMSC(\
|
||||||
sprintf_s(str, bufsize, "%.*f", precision, n),\
|
sprintf_s(str, bufsize, "%.*f", precision, n),\
|
||||||
sprintf(str, "%.*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);\
|
return cptr_copy(str);\
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase)
|
char* toString_f32(f32 n, u8 precision, bool withPostfix, bool uppercase)
|
||||||
_toString_float_impl(48, toString_float32_max_precision)
|
_toString_float_impl(48, toString_f32_max_precision)
|
||||||
|
|
||||||
char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase)
|
char* toString_f64(f64 n, u8 precision, bool withPostfix, bool uppercase)
|
||||||
_toString_float_impl(512, toString_float64_max_precision)
|
_toString_float_impl(512, toString_f64_max_precision)
|
||||||
|
|
||||||
#define byte_to_bits(byte) {\
|
#define byte_to_bits(byte) {\
|
||||||
str[cn++]='0' + (uint8)((byte>>7)&1); /* 8th bit */\
|
str[cn++]='0' + (u8)((byte>>7)&1); /* 8th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>6)&1); /* 7th bit */\
|
str[cn++]='0' + (u8)((byte>>6)&1); /* 7th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>5)&1); /* 6th bit */\
|
str[cn++]='0' + (u8)((byte>>5)&1); /* 6th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>4)&1); /* 5th bit */\
|
str[cn++]='0' + (u8)((byte>>4)&1); /* 5th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>3)&1); /* 4th bit */\
|
str[cn++]='0' + (u8)((byte>>3)&1); /* 4th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>2)&1); /* 3th bit */\
|
str[cn++]='0' + (u8)((byte>>2)&1); /* 3th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>1)&1); /* 2th bit */\
|
str[cn++]='0' + (u8)((byte>>1)&1); /* 2th bit */\
|
||||||
str[cn++]='0' + (uint8)((byte>>0)&1); /* 1th 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* bytes=_bytes;
|
||||||
char* str=malloc(size*8 + (withPrefix?2:0) +1);
|
char* str=malloc(size*8 + (withPrefix?2:0) +1);
|
||||||
uint32 cn=0; // char number
|
u32 cn=0; // char number
|
||||||
if(withPrefix){
|
if(withPrefix){
|
||||||
str[cn++]='0';
|
str[cn++]='0';
|
||||||
str[cn++]='b';
|
str[cn++]='b';
|
||||||
}
|
}
|
||||||
if(inverse){
|
if(inverse){
|
||||||
// byte number
|
// byte number
|
||||||
for(int32 bn=size-1; bn>=0; bn--)
|
for(i32 bn=size-1; bn>=0; bn--)
|
||||||
byte_to_bits(bytes[bn])
|
byte_to_bits(bytes[bn])
|
||||||
} else {
|
} else {
|
||||||
for(int32 bn=0; bn<size; bn++)
|
for(i32 bn=0; bn<size; bn++)
|
||||||
byte_to_bits(bytes[bn])
|
byte_to_bits(bytes[bn])
|
||||||
}
|
}
|
||||||
str[cn]=0;
|
str[cn]=0;
|
||||||
@@ -118,7 +118,7 @@ char* toString_bin(void* _bytes, uint32 size, bool inverse, bool withPrefix){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// converts number from 0 to F to char
|
// converts number from 0 to F to char
|
||||||
char _4bitsHex(uint8 u, bool uppercase){
|
char _4bitsHex(u8 u, bool uppercase){
|
||||||
switch(u){
|
switch(u){
|
||||||
case 0: case 1: case 2: case 3: case 4:
|
case 0: case 1: case 2: case 3: case 4:
|
||||||
case 5: case 6: case 7: case 8: case 9:
|
case 5: case 6: case 7: case 8: case 9:
|
||||||
@@ -133,10 +133,10 @@ char _4bitsHex(uint8 u, bool uppercase){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, bool uppercase){
|
char* toString_hex(void* _bytes, u32 size, bool inverse, bool withPrefix, bool uppercase){
|
||||||
char* bytes=_bytes;
|
char* bytes=_bytes;
|
||||||
char* str=malloc(size*2 + (withPrefix?2:0) + 1);
|
char* str=malloc(size*2 + (withPrefix?2:0) + 1);
|
||||||
uint32 cn=0; // char number
|
u32 cn=0; // char number
|
||||||
if(withPrefix){
|
if(withPrefix){
|
||||||
str[cn++]='0';
|
str[cn++]='0';
|
||||||
str[cn++]='x';
|
str[cn++]='x';
|
||||||
@@ -144,7 +144,7 @@ char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, boo
|
|||||||
// left to right
|
// left to right
|
||||||
if(inverse){
|
if(inverse){
|
||||||
// byte number
|
// byte number
|
||||||
for(int32 bn=size-1; bn>=0; bn--){
|
for(i32 bn=size-1; bn>=0; bn--){
|
||||||
unsigned char byte=bytes[bn];
|
unsigned char byte=bytes[bn];
|
||||||
str[cn++]=_4bitsHex(byte/16, uppercase);
|
str[cn++]=_4bitsHex(byte/16, uppercase);
|
||||||
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
|
// right to left
|
||||||
else {
|
else {
|
||||||
for(int32 bn=0; bn<size; bn++){ // byte number
|
for(i32 bn=0; bn<size; bn++){ // byte number
|
||||||
unsigned char byte=bytes[bn];
|
unsigned char byte=bytes[bn];
|
||||||
str[cn++]=_4bitsHex(byte/16, uppercase);
|
str[cn++]=_4bitsHex(byte/16, uppercase);
|
||||||
str[cn++]=_4bitsHex(byte%16, uppercase);
|
str[cn++]=_4bitsHex(byte%16, uppercase);
|
||||||
@@ -163,11 +163,11 @@ char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define __toString_int_def(BITS) char* __toString_int##BITS(void* _n, uint32 f){\
|
#define __toString_i32_def(BITS) char* __toString_i##BITS(void* _n, u32 f){\
|
||||||
switch(kp_fmt_dataFormat(f)){\
|
switch(kp_fmt_dataFormat(f)){\
|
||||||
case kp_i: ;\
|
case kp_i: ;\
|
||||||
int##BITS n=*(int##BITS*)_n;\
|
i##BITS n=*(i##BITS*)_n;\
|
||||||
return toString_int(n);\
|
return toString_i64(n);\
|
||||||
case kp_b:\
|
case kp_b:\
|
||||||
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||||
case kp_h:\
|
case kp_h:\
|
||||||
@@ -178,16 +178,16 @@ char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, boo
|
|||||||
return NULL;\
|
return NULL;\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
__toString_int_def(8)
|
__toString_i32_def(8)
|
||||||
__toString_int_def(16)
|
__toString_i32_def(16)
|
||||||
__toString_int_def(32)
|
__toString_i32_def(32)
|
||||||
__toString_int_def(64)
|
__toString_i32_def(64)
|
||||||
|
|
||||||
#define __toString_uint_def(BITS) char* __toString_uint##BITS(void* _n, uint32 f){\
|
#define __toString_u_def(BITS) char* __toString_u##BITS(void* _n, u32 f){\
|
||||||
switch(kp_fmt_dataFormat(f)){\
|
switch(kp_fmt_dataFormat(f)){\
|
||||||
case kp_u: ;\
|
case kp_u: ;\
|
||||||
uint##BITS n=*(uint##BITS*)_n;\
|
u##BITS n=*(u##BITS*)_n;\
|
||||||
return toString_uint(n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
return toString_u64(n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
||||||
case kp_b:\
|
case kp_b:\
|
||||||
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||||
case kp_h:\
|
case kp_h:\
|
||||||
@@ -198,16 +198,16 @@ __toString_int_def(64)
|
|||||||
return NULL;\
|
return NULL;\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
__toString_uint_def(8)
|
__toString_u_def(8)
|
||||||
__toString_uint_def(16)
|
__toString_u_def(16)
|
||||||
__toString_uint_def(32)
|
__toString_u_def(32)
|
||||||
__toString_uint_def(64)
|
__toString_u_def(64)
|
||||||
|
|
||||||
#define __toString_float_def(BITS) char* __toString_float##BITS(void* _n, uint32 f){\
|
#define __toString_float_def(BITS) char* __toString_f##BITS(void* _n, u32 f){\
|
||||||
switch(kp_fmt_dataFormat(f)){\
|
switch(kp_fmt_dataFormat(f)){\
|
||||||
case kp_f: ;\
|
case kp_f: ;\
|
||||||
float##BITS n=*(float##BITS*)_n;\
|
f##BITS n=*(f##BITS*)_n;\
|
||||||
return toString_float64(n, toString_float_default_precision, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
return toString_f64(n, toString_float_default_precision, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
||||||
case kp_b:\
|
case kp_b:\
|
||||||
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||||
case kp_h:\
|
case kp_h:\
|
||||||
|
|||||||
@@ -8,39 +8,39 @@ extern "C" {
|
|||||||
|
|
||||||
// char and cstring
|
// char and cstring
|
||||||
// has different output for fmtChar and fmtString
|
// has different output for fmtChar and fmtString
|
||||||
char* __toString_char(void* c, uint32 fmt);
|
char* __toString_char(void* c, u32 fmt);
|
||||||
|
|
||||||
// bool
|
// bool
|
||||||
char* __toString_bool(void* c, uint32 fmt);
|
char* __toString_bool(void* c, u32 fmt);
|
||||||
|
|
||||||
// signed int
|
// signed int
|
||||||
char* toString_int(int64 n);
|
char* toString_i64(i64 n);
|
||||||
char* __toString_int8(void* n, uint32 fmt);
|
char* __toString_i8(void* n, u32 fmt);
|
||||||
char* __toString_int16(void* n, uint32 fmt);
|
char* __toString_i16(void* n, u32 fmt);
|
||||||
char* __toString_int32(void* n, uint32 fmt);
|
char* __toString_i32(void* n, u32 fmt);
|
||||||
char* __toString_int64(void* n, uint32 fmt);
|
char* __toString_i64(void* n, u32 fmt);
|
||||||
|
|
||||||
// unsigned int
|
// unsigned int
|
||||||
char* toString_uint(uint64 n, bool withPostfix, bool uppercase);
|
char* toString_u64(u64 n, bool withPostfix, bool uppercase);
|
||||||
char* __toString_uint8(void* n, uint32 fmt);
|
char* __toString_u8(void* n, u32 fmt);
|
||||||
char* __toString_uint16(void* n, uint32 fmt);
|
char* __toString_u16(void* n, u32 fmt);
|
||||||
char* __toString_uint32(void* n, uint32 fmt);
|
char* __toString_u32(void* n, u32 fmt);
|
||||||
char* __toString_uint64(void* n, uint32 fmt);
|
char* __toString_u64(void* n, u32 fmt);
|
||||||
|
|
||||||
// float
|
// float
|
||||||
#define toString_float32_max_precision 6
|
#define toString_f32_max_precision 6
|
||||||
#define toString_float64_max_precision 15
|
#define toString_f64_max_precision 15
|
||||||
#define toString_float_default_precision 6
|
#define toString_float_default_precision 6
|
||||||
char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
char* toString_f32(f32 n, u8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
||||||
char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
char* toString_f64(f64 n, u8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
||||||
char* __toString_float32(void* n, uint32 fmt);
|
char* __toString_f32(void* n, u32 fmt);
|
||||||
char* __toString_float64(void* n, uint32 fmt);
|
char* __toString_f64(void* n, u32 fmt);
|
||||||
|
|
||||||
|
|
||||||
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
||||||
char* toString_bin(void* bytes, uint32 size, bool inverse, bool withPrefix);
|
char* toString_bin(void* bytes, u32 size, bool inverse, bool withPrefix);
|
||||||
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
||||||
char* toString_hex(void* bytes, uint32 size, bool inverse, bool withPrefix, bool uppercase);
|
char* toString_hex(void* bytes, u32 size, bool inverse, bool withPrefix, bool uppercase);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,16 @@ void ktDescriptors_initKerepTypes(){
|
|||||||
// base types
|
// base types
|
||||||
kt_register(char, NULL, __toString_char);
|
kt_register(char, NULL, __toString_char);
|
||||||
kt_register(bool, NULL, __toString_bool);
|
kt_register(bool, NULL, __toString_bool);
|
||||||
kt_register(float32, NULL, __toString_float32);
|
kt_register(f32, NULL, __toString_f32);
|
||||||
kt_register(float64, NULL, __toString_float64);
|
kt_register(f64, NULL, __toString_f64);
|
||||||
kt_register(int8, NULL, __toString_int8);
|
kt_register(i8, NULL, __toString_i8);
|
||||||
kt_register(uint8, NULL, __toString_uint8);
|
kt_register(u8, NULL, __toString_u8);
|
||||||
kt_register(int16, NULL, __toString_int16);
|
kt_register(i16, NULL, __toString_i16);
|
||||||
kt_register(uint16, NULL, __toString_uint16);
|
kt_register(u16, NULL, __toString_u16);
|
||||||
kt_register(int32, NULL, __toString_int32);
|
kt_register(i32, NULL, __toString_i32);
|
||||||
kt_register(uint32, NULL, __toString_uint32);
|
kt_register(u32, NULL, __toString_u32);
|
||||||
kt_register(int64, NULL, __toString_int64);
|
kt_register(i64, NULL, __toString_i64);
|
||||||
kt_register(uint64, NULL, __toString_uint64);
|
kt_register(u64, NULL, __toString_u64);
|
||||||
|
|
||||||
// ktDescriptor
|
// ktDescriptor
|
||||||
kt_register(ktDescriptor, NULL, NULL);
|
kt_register(ktDescriptor, NULL, NULL);
|
||||||
@@ -31,30 +31,30 @@ void ktDescriptors_initKerepTypes(){
|
|||||||
// base type arrays
|
// base type arrays
|
||||||
kt_register(Array_char, (freeMembers_t)Array_char_free, NULL);
|
kt_register(Array_char, (freeMembers_t)Array_char_free, NULL);
|
||||||
kt_register(Array_bool, (freeMembers_t)Array_bool_free, NULL);
|
kt_register(Array_bool, (freeMembers_t)Array_bool_free, NULL);
|
||||||
kt_register(Array_float32, (freeMembers_t)Array_float32_free, NULL);
|
kt_register(Array_f32, (freeMembers_t)Array_f32_free, NULL);
|
||||||
kt_register(Array_float64, (freeMembers_t)Array_float64_free, NULL);
|
kt_register(Array_f64, (freeMembers_t)Array_f64_free, NULL);
|
||||||
kt_register(Array_int8, (freeMembers_t)Array_int8_free, NULL);
|
kt_register(Array_i8, (freeMembers_t)Array_i8_free, NULL);
|
||||||
kt_register(Array_uint8, (freeMembers_t)Array_uint8_free, NULL);
|
kt_register(Array_u8, (freeMembers_t)Array_u8_free, NULL);
|
||||||
kt_register(Array_int16, (freeMembers_t)Array_int16_free, NULL);
|
kt_register(Array_i16, (freeMembers_t)Array_i16_free, NULL);
|
||||||
kt_register(Array_uint16, (freeMembers_t)Array_uint16_free, NULL);
|
kt_register(Array_u16, (freeMembers_t)Array_u16_free, NULL);
|
||||||
kt_register(Array_int32, (freeMembers_t)Array_int32_free, NULL);
|
kt_register(Array_i32, (freeMembers_t)Array_i32_free, NULL);
|
||||||
kt_register(Array_uint32, (freeMembers_t)Array_uint32_free, NULL);
|
kt_register(Array_u32, (freeMembers_t)Array_u32_free, NULL);
|
||||||
kt_register(Array_int64, (freeMembers_t)Array_int64_free, NULL);
|
kt_register(Array_i64, (freeMembers_t)Array_i64_free, NULL);
|
||||||
kt_register(Array_uint64, (freeMembers_t)Array_uint64_free, NULL);
|
kt_register(Array_u64, (freeMembers_t)Array_u64_free, NULL);
|
||||||
|
|
||||||
// base type autoarrs
|
// base type autoarrs
|
||||||
kt_register(Autoarr_char, ____Autoarr_free_char, NULL);
|
kt_register(Autoarr_char, ____Autoarr_free_char, NULL);
|
||||||
kt_register(Autoarr_bool, ____Autoarr_free_bool, NULL);
|
kt_register(Autoarr_bool, ____Autoarr_free_bool, NULL);
|
||||||
kt_register(Autoarr_float32, ____Autoarr_free_float32, NULL);
|
kt_register(Autoarr_f32, ____Autoarr_free_f32, NULL);
|
||||||
kt_register(Autoarr_float64, ____Autoarr_free_float64, NULL);
|
kt_register(Autoarr_f64, ____Autoarr_free_f64, NULL);
|
||||||
kt_register(Autoarr_int8, ____Autoarr_free_int8, NULL);
|
kt_register(Autoarr_i8, ____Autoarr_free_i8, NULL);
|
||||||
kt_register(Autoarr_uint8, ____Autoarr_free_uint8, NULL);
|
kt_register(Autoarr_u8, ____Autoarr_free_u8, NULL);
|
||||||
kt_register(Autoarr_int16, ____Autoarr_free_int16, NULL);
|
kt_register(Autoarr_i16, ____Autoarr_free_i16, NULL);
|
||||||
kt_register(Autoarr_uint16, ____Autoarr_free_uint16, NULL);
|
kt_register(Autoarr_u16, ____Autoarr_free_u16, NULL);
|
||||||
kt_register(Autoarr_int32, ____Autoarr_free_int32, NULL);
|
kt_register(Autoarr_i32, ____Autoarr_free_i32, NULL);
|
||||||
kt_register(Autoarr_uint32, ____Autoarr_free_uint32, NULL);
|
kt_register(Autoarr_u32, ____Autoarr_free_u32, NULL);
|
||||||
kt_register(Autoarr_int64, ____Autoarr_free_int64, NULL);
|
kt_register(Autoarr_i64, ____Autoarr_free_i64, NULL);
|
||||||
kt_register(Autoarr_uint64, ____Autoarr_free_uint64, NULL);
|
kt_register(Autoarr_u64, ____Autoarr_free_u64, NULL);
|
||||||
|
|
||||||
// Unitype
|
// Unitype
|
||||||
kt_register(Unitype, __UnitypePtr_free, NULL);
|
kt_register(Unitype, __UnitypePtr_free, NULL);
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ extern "C" {
|
|||||||
#include "ktid.h"
|
#include "ktid.h"
|
||||||
|
|
||||||
typedef void (*freeMembers_t)(void*);
|
typedef void (*freeMembers_t)(void*);
|
||||||
typedef char* (*toString_t)(void* obj, uint32 fmt);
|
typedef char* (*toString_t)(void* obj, u32 fmt);
|
||||||
typedef struct ktDescriptor{
|
typedef struct ktDescriptor{
|
||||||
char* name;
|
char* name;
|
||||||
ktid id;
|
ktid id;
|
||||||
uint16 size;
|
u16 size;
|
||||||
freeMembers_t freeMembers; // NULL or function which frees all struct members
|
freeMembers_t freeMembers; // NULL or function which frees all struct members
|
||||||
toString_t toString; // NULL or function which generates string representaion of object
|
toString_t toString; // NULL or function which generates string representaion of object
|
||||||
} ktDescriptor;
|
} ktDescriptor;
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ ktid ktid_Null=-1;
|
|||||||
|
|
||||||
ktid_define(char);
|
ktid_define(char);
|
||||||
ktid_define(bool);
|
ktid_define(bool);
|
||||||
ktid_define(float32);
|
ktid_define(f32);
|
||||||
ktid_define(float64);
|
ktid_define(f64);
|
||||||
ktid_define(int8);
|
ktid_define(i8);
|
||||||
ktid_define(uint8);
|
ktid_define(u8);
|
||||||
ktid_define(int16);
|
ktid_define(i16);
|
||||||
ktid_define(uint16);
|
ktid_define(u16);
|
||||||
ktid_define(int32);
|
ktid_define(i32);
|
||||||
ktid_define(uint32);
|
ktid_define(u32);
|
||||||
ktid_define(int64);
|
ktid_define(i64);
|
||||||
ktid_define(uint64);
|
ktid_define(u64);
|
||||||
|
|
||||||
ktid_define(ktDescriptor);
|
ktid_define(ktDescriptor);
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ void ktDescriptors_endInit(){
|
|||||||
kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
|
kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kt_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, uint32)){
|
void __kt_register(char* name, i16 size, void (*freeMembers)(void*), char* (*toString)(void*, u32)){
|
||||||
ktDescriptor typeDesc={
|
ktDescriptor typeDesc={
|
||||||
.name=name,
|
.name=name,
|
||||||
.size=size,
|
.size=size,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ extern "C" {
|
|||||||
#include "ktDescriptor.h"
|
#include "ktDescriptor.h"
|
||||||
|
|
||||||
extern ktid ktid_last;
|
extern ktid ktid_last;
|
||||||
void __kt_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, uint32));
|
void __kt_register(char* name, i16 size, void (*freeMembers)(void*), char* (*toString)(void*, u32));
|
||||||
|
|
||||||
#define kt_register(TYPE, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\
|
#define kt_register(TYPE, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\
|
||||||
__kt_register(#TYPE, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\
|
__kt_register(#TYPE, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\
|
||||||
@@ -30,16 +30,16 @@ extern ktid ktid_Null;
|
|||||||
|
|
||||||
ktid_declare(char);
|
ktid_declare(char);
|
||||||
ktid_declare(bool);
|
ktid_declare(bool);
|
||||||
ktid_declare(float32);
|
ktid_declare(f32);
|
||||||
ktid_declare(float64);
|
ktid_declare(f64);
|
||||||
ktid_declare(int8);
|
ktid_declare(i8);
|
||||||
ktid_declare(uint8);
|
ktid_declare(u8);
|
||||||
ktid_declare(int16);
|
ktid_declare(i16);
|
||||||
ktid_declare(uint16);
|
ktid_declare(u16);
|
||||||
ktid_declare(int32);
|
ktid_declare(i32);
|
||||||
ktid_declare(uint32);
|
ktid_declare(u32);
|
||||||
ktid_declare(int64);
|
ktid_declare(i64);
|
||||||
ktid_declare(uint64);
|
ktid_declare(u64);
|
||||||
|
|
||||||
ktid_declare(ktDescriptor);
|
ktid_declare(ktDescriptor);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../std.h"
|
#include "../std.h"
|
||||||
typedef uint16 ktid;
|
typedef u16 ktid;
|
||||||
|
|
||||||
#define ktid_name(TYPE) ktid_##TYPE
|
#define ktid_name(TYPE) ktid_##TYPE
|
||||||
#define ktid_ptrName(TYPE) ktid_##TYPE##_Ptr
|
#define ktid_ptrName(TYPE) ktid_##TYPE##_Ptr
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ void Unitype_free(Unitype u){
|
|||||||
}
|
}
|
||||||
void __UnitypePtr_free(void* u) { Unitype_free(*(Unitype*)u); }
|
void __UnitypePtr_free(void* u) { Unitype_free(*(Unitype*)u); }
|
||||||
|
|
||||||
char* toString_Unitype(void* _u, uint32 fmt){
|
char* toString_Unitype(void* _u, u32 fmt){
|
||||||
Unitype* u=_u;
|
Unitype* u=_u;
|
||||||
ktDescriptor type=ktDescriptor_get(u->typeId);
|
ktDescriptor type=ktDescriptor_get(u->typeId);
|
||||||
char* valuestr=type.toString(_u, fmt);
|
char* valuestr=type.toString(_u, fmt);
|
||||||
@@ -30,11 +30,11 @@ char* sprintuni(Unitype v){
|
|||||||
ktDescriptor type=ktDescriptor_get(v.typeId);
|
ktDescriptor type=ktDescriptor_get(v.typeId);
|
||||||
if(v.typeId==ktid_Null)
|
if(v.typeId==ktid_Null)
|
||||||
sprintf_s(buf, BUFSIZE, "{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);
|
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);
|
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);
|
sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%lld", "%ld") "}", type.name,v.Int64);
|
||||||
else if(v.typeId==ktid_ptrName(char)){
|
else if(v.typeId==ktid_ptrName(char)){
|
||||||
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
|
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct Unitype{
|
typedef struct Unitype{
|
||||||
union {
|
union {
|
||||||
int64 Int64;
|
i64 Int64;
|
||||||
uint64 UInt64;
|
u64 UInt64;
|
||||||
double Float64;
|
f64 Float64;
|
||||||
bool Bool;
|
bool Bool;
|
||||||
void* VoidPtr;
|
void* VoidPtr;
|
||||||
char Bytes[8];
|
char Bytes[8];
|
||||||
@@ -24,9 +24,9 @@ ktid_declare(Unitype);
|
|||||||
#define __UniDef(FIELD, TYPE, VAL) (Unitype){\
|
#define __UniDef(FIELD, TYPE, VAL) (Unitype){\
|
||||||
.FIELD=VAL, .typeId=ktid_name(TYPE), .allocatedInHeap=false}
|
.FIELD=VAL, .typeId=ktid_name(TYPE), .allocatedInHeap=false}
|
||||||
|
|
||||||
#define UniInt64(VAL) __UniDef(Int64, int64, VAL)
|
#define UniInt64(VAL) __UniDef(Int64, i64, VAL)
|
||||||
#define UniUInt64(VAL) __UniDef(UInt64, uint64, VAL)
|
#define UniUInt64(VAL) __UniDef(UInt64, u64, VAL)
|
||||||
#define UniFloat64(VAL) __UniDef(Float64, float64, VAL)
|
#define UniFloat64(VAL) __UniDef(Float64, f64, VAL)
|
||||||
#define UniBool(VAL) __UniDef(Bool, bool, VAL)
|
#define UniBool(VAL) __UniDef(Bool, bool, VAL)
|
||||||
|
|
||||||
#define UniStackPtr(TYPE, VAL) (Unitype){\
|
#define UniStackPtr(TYPE, VAL) (Unitype){\
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ 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.
|
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 |
|
| type | placeholder |
|
||||||
|-------------------------|-------------------------|
|
|----------------|-------------------------|
|
||||||
| int8 / int16 / int32 | %i / %d |
|
| i8 / i16 / i32 | %i / %d |
|
||||||
| int64 | %li / %ld / %lld / %lli |
|
| i64 | %li / %ld / %lld / %lli |
|
||||||
| uint8 / uint16 / uint32 | %u |
|
| u8 / u16 / u32 | %u |
|
||||||
| uint64 | %lu / %llu |
|
| u64 | %lu / %llu |
|
||||||
| float32 / float64 | %f |
|
| f32 / f64 | %f |
|
||||||
| char | %c |
|
| char | %c |
|
||||||
| char[] | %s |
|
| char[] | %s |
|
||||||
| void\* | %p / %x |
|
| void\* | %p / %x |
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ ktid __typeFromFormat(kp_fmt f){
|
|||||||
case kp_i:
|
case kp_i:
|
||||||
case kp_h:
|
case kp_h:
|
||||||
case kp_b:
|
case kp_b:
|
||||||
return ktid_name(int64);
|
return ktid_name(i64);
|
||||||
case kp_u:
|
case kp_u:
|
||||||
return ktid_name(uint64);
|
return ktid_name(u64);
|
||||||
case kp_f:
|
case kp_f:
|
||||||
return ktid_name(float64);
|
return ktid_name(f64);
|
||||||
case kp_c:
|
case kp_c:
|
||||||
return ktid_char;
|
return ktid_char;
|
||||||
case kp_s:
|
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)));
|
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%2 != 0) safethrow("kprint recieved non-even number of arguments",;);
|
||||||
if(n > 32) safethrow("kprint recieved >32 number of arguments",;);
|
if(n > 32) safethrow("kprint recieved >32 number of arguments",;);
|
||||||
return MaybeNull;
|
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), _,;);
|
try(check_argsN(n), _,;);
|
||||||
n/=2;
|
n/=2;
|
||||||
StringBuilder* strb=StringBuilder_create();
|
StringBuilder* strb=StringBuilder_create();
|
||||||
for(uint8 i=0; i<n; i++){
|
for(u8 i=0; i<n; i++){
|
||||||
try(__next_toString(formats[i], &objects[i]),mStr,;);
|
try(__next_toString(formats[i], &objects[i]),mStr,;);
|
||||||
StringBuilder_append_cptr(strb, mStr.value.VoidPtr);
|
StringBuilder_append_cptr(strb, mStr.value.VoidPtr);
|
||||||
Unitype_free(mStr.value);
|
Unitype_free(mStr.value);
|
||||||
@@ -53,10 +53,10 @@ Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
|||||||
return SUCCESS(UniHeapPtr(char, rezult));
|
return SUCCESS(UniHeapPtr(char, rezult));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe __kfprint(FILE* file, uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
Maybe __kfprint(FILE* file, u8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||||
try(check_argsN(n), _,;);
|
try(check_argsN(n), _,;);
|
||||||
n/=2;
|
n/=2;
|
||||||
for(uint8 i=0; i<n; i++){
|
for(u8 i=0; i<n; i++){
|
||||||
try(__next_toString(formats[i], &objects[i]),maybeStr,;);
|
try(__next_toString(formats[i], &objects[i]),maybeStr,;);
|
||||||
if(fputs(maybeStr.value.VoidPtr, file)==EOF)
|
if(fputs(maybeStr.value.VoidPtr, file)==EOF)
|
||||||
safethrow("can't write string to file", Unitype_free(maybeStr.value));
|
safethrow("can't write string to file", Unitype_free(maybeStr.value));
|
||||||
@@ -66,10 +66,10 @@ Maybe __kfprint(FILE* file, uint8 n, kp_fmt* formats, __kp_value_union* objects)
|
|||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||||
tryLast(check_argsN(n), _);
|
tryLast(check_argsN(n), _);
|
||||||
n/=2;
|
n/=2;
|
||||||
for(uint8 i=0; i<n; i++){
|
for(u8 i=0; i<n; i++){
|
||||||
kp_fmt fmt=formats[i];
|
kp_fmt fmt=formats[i];
|
||||||
kprint_setColor(fmt);
|
kprint_setColor(fmt);
|
||||||
tryLast(__next_toString(fmt, &objects[i]),maybeStr);
|
tryLast(__next_toString(fmt, &objects[i]),maybeStr);
|
||||||
@@ -145,13 +145,13 @@ void kprint_setColor(kp_fmt f){
|
|||||||
#else
|
#else
|
||||||
void kprint_setColor(kp_fmt f){
|
void kprint_setColor(kp_fmt f){
|
||||||
if(kp_fmt_fgColorSet(f)){
|
if(kp_fmt_fgColorSet(f)){
|
||||||
uint8 fg=(f&0x0f000000)>>24;
|
u8 fg=(f&0x0f000000)>>24;
|
||||||
if(fg<8) fg+=30;
|
if(fg<8) fg+=30;
|
||||||
else fg+=90-8;
|
else fg+=90-8;
|
||||||
printf("\e[%um", fg);
|
printf("\e[%um", fg);
|
||||||
}
|
}
|
||||||
if(kp_fmt_bgColorSet(f)){
|
if(kp_fmt_bgColorSet(f)){
|
||||||
uint8 bg=(f&0x00f00000)>>20;
|
u8 bg=(f&0x00f00000)>>20;
|
||||||
if(bg<8) bg+=40;
|
if(bg<8) bg+=40;
|
||||||
else bg+=100-8;
|
else bg+=100-8;
|
||||||
printf("\e[%um", bg);
|
printf("\e[%um", bg);
|
||||||
@@ -159,13 +159,13 @@ void kprint_setColor(kp_fmt f){
|
|||||||
}
|
}
|
||||||
#endif
|
#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);
|
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
||||||
if(!typeDesc.toString)
|
if(!typeDesc.toString)
|
||||||
safethrow("type descriptor doesnt have toString() func",;);
|
safethrow("type descriptor doesnt have toString() func",;);
|
||||||
StringBuilder* strb=StringBuilder_create();
|
StringBuilder* strb=StringBuilder_create();
|
||||||
StringBuilder_append_char(strb, '[');
|
StringBuilder_append_char(strb, '[');
|
||||||
for (uint16 e=1; e<count; e++){
|
for (u16 e=1; e<count; e++){
|
||||||
StringBuilder_append_char(strb, ' ');
|
StringBuilder_append_char(strb, ' ');
|
||||||
char* elStr=typeDesc.toString(array+typeDesc.size*e, &format);
|
char* elStr=typeDesc.toString(array+typeDesc.size*e, &format);
|
||||||
StringBuilder_append_cptr(strb, elStr);
|
StringBuilder_append_cptr(strb, elStr);
|
||||||
|
|||||||
@@ -15,23 +15,23 @@ This file looks like a mess, but all cotnent here just solves the problem of put
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
int64 i64;
|
i64 i64;
|
||||||
uint64 u64;
|
u64 u64;
|
||||||
float64 f64;
|
f64 f64;
|
||||||
void* ptr;
|
void* ptr;
|
||||||
} __kp_value_union;
|
} __kp_value_union;
|
||||||
|
|
||||||
|
|
||||||
static inline __kp_value_union __kpVU_f(float64 f) { return (__kp_value_union){ .f64=f }; }
|
static inline __kp_value_union __kpVU_f(f64 f) { return (__kp_value_union){ .f64=f }; }
|
||||||
static inline __kp_value_union __kpVU_i(int64 f) { return (__kp_value_union){ .i64=f }; }
|
static inline __kp_value_union __kpVU_i(i64 f) { return (__kp_value_union){ .i64=f }; }
|
||||||
|
|
||||||
#define __kpVU_selectType(V) _Generic(V, float: __kpVU_f, double: __kpVU_f, default: __kpVU_i)(V)
|
#define __kpVU_selectType(V) _Generic(V, float: __kpVU_f, f64: __kpVU_f, default: __kpVU_i)(V)
|
||||||
|
|
||||||
#define __kpVU(V) __kpVU_selectType(V)
|
#define __kpVU(V) __kpVU_selectType(V)
|
||||||
|
|
||||||
#define __kp_argsToFmts8(\
|
#define __kp_argsToFmts8(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
||||||
((int32[]){ a0,a2,a4,a6 })
|
((i32[]){ a0,a2,a4,a6 })
|
||||||
#define __kp_argsToObjs8(\
|
#define __kp_argsToObjs8(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
||||||
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7) })
|
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7) })
|
||||||
@@ -39,7 +39,7 @@ static inline __kp_value_union __kpVU_i(int64 f) { return (__kp_value_union){ .i
|
|||||||
#define __kp_argsToFmts16(\
|
#define __kp_argsToFmts16(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
||||||
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14 })
|
((i32[]){ a0,a2,a4,a6,a8,a10,a12,a14 })
|
||||||
#define __kp_argsToObjs16(\
|
#define __kp_argsToObjs16(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
||||||
@@ -50,7 +50,7 @@ static inline __kp_value_union __kpVU_i(int64 f) { return (__kp_value_union){ .i
|
|||||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||||
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
||||||
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14,a16,a18,a20,a22,a24,a26,a28,a30 })
|
((i32[]){ a0,a2,a4,a6,a8,a10,a12,a14,a16,a18,a20,a22,a24,a26,a28,a30 })
|
||||||
#define __kp_argsToObjs32(\
|
#define __kp_argsToObjs32(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||||
@@ -71,7 +71,7 @@ static inline __kp_value_union __kpVU_i(int64 f) { return (__kp_value_union){ .i
|
|||||||
__kp_argsToObjs32(ARGS))
|
__kp_argsToObjs32(ARGS))
|
||||||
|
|
||||||
|
|
||||||
Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
Maybe __ksprint(u8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||||
|
|
||||||
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
||||||
///@returns Maybe<char*>
|
///@returns Maybe<char*>
|
||||||
@@ -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*/
|
/*-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 FD FILE*
|
||||||
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
/// @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))\
|
__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 !!!
|
///can use non-catchable throw !!!
|
||||||
///@param ARGS kp_fmt, value, kp_fmt, value...
|
///@param ARGS kp_fmt, value, kp_fmt, value...
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ extern "C" {
|
|||||||
#include "../base/type_system/ktid.h"
|
#include "../base/type_system/ktid.h"
|
||||||
|
|
||||||
/// kprint_format
|
/// kprint_format
|
||||||
typedef uint32 kp_fmt;
|
typedef u32 kp_fmt;
|
||||||
|
|
||||||
PACK_ENUM(kp_dataFmt,
|
PACK_ENUM(kp_dataFmt,
|
||||||
// 00000000 00000000 00000000 00000000
|
// 00000000 00000000 00000000 00000000
|
||||||
|
|||||||
@@ -55,14 +55,16 @@ bgColorSet─┘││ │ bgColor └data format
|
|||||||
## Data format
|
## Data format
|
||||||
|
|
||||||
| format | possible flags | data types | hex value | bin value |
|
| format | possible flags | data types | hex value | bin value |
|
||||||
|-----------|----------------|------------|-----------|-----------|
|
|-----------|----------------|------------|------------|-----------|
|
||||||
| kp_i | | int8... int64 | 0x00000000 | 00000000 00000000... |
|
| kp_i | | i8... i64 | 0x00000000 | 00000000 00000000... |
|
||||||
| kp_u | Postfix, Upper | uint8... uint64 | 0x00010000 | 00000000 00000001... |
|
| kp_u | Postfix, Upper | u8... u64 | 0x00010000 | 00000000 00000001... |
|
||||||
| kp_h | Prefix, Upper | any | 0x00020000 | 00000000 00000010... |
|
| kp_h | Prefix, Upper | any | 0x00020000 | 00000000 00000010... |
|
||||||
| kp_b | Prefix | any | 0x00030000 | 00000000 00000011... |
|
| kp_b | Prefix | any | 0x00030000 | 00000000 00000011... |
|
||||||
| kp_f | Postfix, Upper | float32, float64 | 0x00040000 | 00000000 00000100... |
|
| kp_f | Postfix, Upper | f32, f64 | 0x00040000 | 00000000 00000100... |
|
||||||
| kp_c | | char | 0x00050000 | 00000000 00000101... |
|
| kp_c | | char | 0x00050000 | 00000000 00000101... |
|
||||||
| kp_sing | | char* | 0x00060000 | 00000000 00000110... |
|
| 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*
|
### *Flags*
|
||||||
| flag | hex value | bin value |
|
| flag | hex value | bin value |
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#if defined(_WIN64) || defined(_WIN32)
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
WORD unixColorToWin(uint8 c){
|
WORD unixColorToWin(u8 c){
|
||||||
switch(c){
|
switch(c){
|
||||||
//foreground
|
//foreground
|
||||||
case 30: return 0;
|
case 30: return 0;
|
||||||
@@ -49,7 +49,7 @@ WORD unixColorToWin(uint8 c){
|
|||||||
void kprintf(const char* format, ...){
|
void kprintf(const char* format, ...){
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, format);
|
va_start(vl, format);
|
||||||
uint32 i=0;
|
u32 i=0;
|
||||||
for(char c=format[i++]; c!=0; c=format[i++]){
|
for(char c=format[i++]; c!=0; c=format[i++]){
|
||||||
if(c=='%'){
|
if(c=='%'){
|
||||||
char* argstr=NULL;
|
char* argstr=NULL;
|
||||||
@@ -58,18 +58,18 @@ void kprintf(const char* format, ...){
|
|||||||
format_escape_seq:
|
format_escape_seq:
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'u':
|
case 'u':
|
||||||
argstr=toString_uint(
|
argstr=toString_u64(
|
||||||
l ? va_arg(vl, uint64) : va_arg(vl, uint32)
|
l ? va_arg(vl, u64) : va_arg(vl, u32)
|
||||||
,0,0);
|
,0,0);
|
||||||
break;
|
break;
|
||||||
case 'i': case 'd':
|
case 'i': case 'd':
|
||||||
argstr=toString_int(
|
argstr=toString_i64(
|
||||||
l ? va_arg(vl, int64) : va_arg(vl, int32)
|
l ? va_arg(vl, i64) : va_arg(vl, i32)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
// float32 is promoted to float64 when passed through '...'
|
// f32 is promoted to f64 when passed through '...'
|
||||||
argstr=toString_float64(va_arg(vl, float64), toString_float_default_precision,0,0);
|
argstr=toString_f64(va_arg(vl, f64), toString_float_default_precision,0,0);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
l=true;
|
l=true;
|
||||||
@@ -78,7 +78,7 @@ void kprintf(const char* format, ...){
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'x': ;
|
case 'x': ;
|
||||||
uint64 px=va_arg(vl, uint64);
|
u64 px=va_arg(vl, u64);
|
||||||
argstr=toString_hex(&px,getEndian()==LittleEndian,sizeof(px),1,0);
|
argstr=toString_hex(&px,getEndian()==LittleEndian,sizeof(px),1,0);
|
||||||
break;
|
break;
|
||||||
case 's': ;
|
case 's': ;
|
||||||
@@ -108,8 +108,8 @@ void kprintf(const char* format, ...){
|
|||||||
IFWIN(
|
IFWIN(
|
||||||
({
|
({
|
||||||
if((c=format[i++])=='['){
|
if((c=format[i++])=='['){
|
||||||
uint8 colorUnix=0;
|
u8 colorUnix=0;
|
||||||
for(int8 n=0; n<6 && c!=0; n++){
|
for(i8 n=0; n<6 && c!=0; n++){
|
||||||
c=format[i++];
|
c=format[i++];
|
||||||
switch (c){
|
switch (c){
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ extern "C" {
|
|||||||
/*
|
/*
|
||||||
You can choose any algorithm that has required functions:
|
You can choose any algorithm that has required functions:
|
||||||
|
|
||||||
some_alg32_statePtr some_alg32_init(uint32 seed);
|
some_alg32_statePtr some_alg32_init(u32 seed);
|
||||||
uint32 some_alg32_next(some_alg32_statePtr);
|
u32 some_alg32_next(some_alg32_statePtr);
|
||||||
void some_alg32_free(some_alg32_statePtr);
|
void some_alg32_free(some_alg32_statePtr);
|
||||||
|
|
||||||
#define KRAND_ALG32_init some_alg32_init
|
#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); }
|
#define __krand_next_definition(VALUE_SIZE) { return from+KRAND_ALG##VALUE_SIZE##_next(state)%(to-from); }
|
||||||
|
|
||||||
// ready-to-use functions
|
// ready-to-use functions
|
||||||
static inline int8 krand_next8 (krand_statePtr state, int8 from, int8 to) __krand_next_definition(32)
|
static inline i8 krand_next8 (krand_statePtr state, i8 from, i8 to) __krand_next_definition(32)
|
||||||
static inline int16 krand_next16(krand_statePtr state, int16 from, int16 to) __krand_next_definition(32)
|
static inline i16 krand_next16(krand_statePtr state, i16 from, i16 to) __krand_next_definition(32)
|
||||||
static inline int32 krand_next32(krand_statePtr state, int32 from, int32 to) __krand_next_definition(32)
|
static inline i32 krand_next32(krand_statePtr state, i32 from, i32 to) __krand_next_definition(32)
|
||||||
static inline int64 krand_next64(krand_statePtr state, int64 from, int64 to) __krand_next_definition(64)
|
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
|
// 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 f32 krand_nextFloat32(krand_statePtr state) {return (u32)KRAND_ALG32_next(state)/0xffffffff; }
|
||||||
static inline float64 krand_nextFloat64(krand_statePtr state) {return KRAND_ALG64_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
|
///@param chance (0-1.0) is probability of success
|
||||||
static inline bool fate(krand_statePtr state,float chance){
|
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;
|
return KRAND_ALG32_next(state)%limit == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,18 @@ generator.
|
|||||||
|
|
||||||
// The state can be seeded with any (upto) 64 bit integer value.
|
// 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));
|
splitmix64_state* state=malloc(sizeof(splitmix64_state));
|
||||||
*state=seed;
|
*state=seed;
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 splitmix64_next(void* _state) {
|
u64 splitmix64_next(void* _state) {
|
||||||
splitmix64_state* state=_state;
|
splitmix64_state* state=_state;
|
||||||
// increment the state variable
|
// increment the state variable
|
||||||
*state += 0x9e3779b97f4a7c15;
|
*state += 0x9e3779b97f4a7c15;
|
||||||
// copy the state to a working variable
|
// 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
|
// xor the variable with the variable right bit shifted 30 then multiply by a constant
|
||||||
z = (z ^ (z>>30)) * 0xbf58476d1ce4e5b9;
|
z = (z ^ (z>>30)) * 0xbf58476d1ce4e5b9;
|
||||||
// xor the variable with the variable right bit shifted 27 then multiply by a constant
|
// xor the variable with the variable right bit shifted 27 then multiply by a constant
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ extern "C" {
|
|||||||
|
|
||||||
#include "../../base/base.h"
|
#include "../../base/base.h"
|
||||||
|
|
||||||
typedef uint64 splitmix64_state;
|
typedef u64 splitmix64_state;
|
||||||
typedef void* splitmix64_statePtr;
|
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)); }
|
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) {
|
static inline void splitmix64_free(splitmix64_statePtr state) {
|
||||||
free(state);
|
free(state);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ extern "C" {
|
|||||||
#include "../../splitmix64/splitmix64.h"
|
#include "../../splitmix64/splitmix64.h"
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint64 merged;
|
u64 merged;
|
||||||
uint32 s[2];
|
u32 s[2];
|
||||||
} xoroshiro64_state;
|
} xoroshiro64_state;
|
||||||
typedef void* xoroshiro64_statePtr;
|
typedef void* xoroshiro64_statePtr;
|
||||||
|
|
||||||
xoroshiro64_statePtr xoroshiro64_init(uint64 seed);
|
xoroshiro64_statePtr xoroshiro64_init(u64 seed);
|
||||||
#define xoroshiro64star_init xoroshiro64_init
|
#define xoroshiro64star_init xoroshiro64_init
|
||||||
#define xoroshiro64starstar_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 xoroshiro64star_initFromTime xoroshiro64_initFromTime
|
||||||
#define xoroshiro64starstar_initFromTime xoroshiro64_initFromTime
|
#define xoroshiro64starstar_initFromTime xoroshiro64_initFromTime
|
||||||
|
|
||||||
uint32 xoroshiro64star_next(xoroshiro64_statePtr);
|
u32 xoroshiro64star_next(xoroshiro64_statePtr);
|
||||||
uint32 xoroshiro64starstar_next(xoroshiro64_statePtr);
|
u32 xoroshiro64starstar_next(xoroshiro64_statePtr);
|
||||||
|
|
||||||
static inline void xoroshiro64_free(xoroshiro64_statePtr state) {
|
static inline void xoroshiro64_free(xoroshiro64_statePtr state) {
|
||||||
free(state);
|
free(state);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
This is xoroshiro64* 1.0, our best and fastest 32-bit small-state
|
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
|
generator for 32-bit floating-poi32 numbers. We suggest to use its
|
||||||
upper bits for floating-point generation, as it is slightly faster than
|
upper bits for floating-poi32 generation, as it is slightly faster than
|
||||||
xoroshiro64**. It passes all tests we are aware of except for linearity
|
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
|
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
|
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.
|
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));
|
return (x << k) | (x >> (32 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 xoroshiro64star_next(void* _state) {
|
u32 xoroshiro64star_next(void* _state) {
|
||||||
xoroshiro64_state* state=_state;
|
xoroshiro64_state* state=_state;
|
||||||
const uint32 s0 = state->s[0];
|
const u32 s0 = state->s[0];
|
||||||
uint32 s1 = state->s[1];
|
u32 s1 = state->s[1];
|
||||||
const uint32 result = s0 * 0x9E3779BB;
|
const u32 result = s0 * 0x9E3779BB;
|
||||||
|
|
||||||
s1 ^= s0;
|
s1 ^= s0;
|
||||||
state->s[0] = rotl(s0, 26) ^ s1 ^ (s1 << 9); // a, b
|
state->s[0] = rotl(s0, 26) ^ s1 ^ (s1 << 9); // a, b
|
||||||
@@ -40,7 +40,7 @@ uint32 xoroshiro64star_next(void* _state) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* xoroshiro64_init(uint64 seed){
|
void* xoroshiro64_init(u64 seed){
|
||||||
xoroshiro64_state* state=malloc(sizeof(xoroshiro64_state));
|
xoroshiro64_state* state=malloc(sizeof(xoroshiro64_state));
|
||||||
splitmix64_state* splitmix=splitmix64_init(seed);
|
splitmix64_state* splitmix=splitmix64_init(seed);
|
||||||
state->merged=splitmix64_next(splitmix);
|
state->merged=splitmix64_next(splitmix);
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
The state must be seeded so that it is not everywhere zero. */
|
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));
|
return (x << k) | (x >> (32 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 xoroshiro64starstar_next(void* _state) {
|
u32 xoroshiro64starstar_next(void* _state) {
|
||||||
xoroshiro64_state* state=_state;
|
xoroshiro64_state* state=_state;
|
||||||
const uint32 s0 = state->s[0];
|
const u32 s0 = state->s[0];
|
||||||
uint32 s1 = state->s[1];
|
u32 s1 = state->s[1];
|
||||||
const uint32 result = rotl(s0 * 0x9E3779BB, 5) * 5;
|
const u32 result = rotl(s0 * 0x9E3779BB, 5) * 5;
|
||||||
|
|
||||||
s1 ^= s0;
|
s1 ^= s0;
|
||||||
state->s[0] = rotl(s0, 26) ^ s1 ^ (s1 << 9); // a, b
|
state->s[0] = rotl(s0, 26) ^ s1 ^ (s1 << 9); // a, b
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint32 s[2];
|
u32 s[2];
|
||||||
} xoroshiro128_state;
|
} xoroshiro128_state;
|
||||||
typedef void* xoroshiro128_statePtr;
|
typedef void* xoroshiro128_statePtr;
|
||||||
|
|
||||||
xoroshiro128_statePtr xoroshiro128_init(uint64 seed);
|
xoroshiro128_statePtr xoroshiro128_init(u64 seed);
|
||||||
#define xoroshiro128plus_init xoroshiro128_init
|
#define xoroshiro128plus_init xoroshiro128_init
|
||||||
#define xoroshiro128plusplus_init xoroshiro128_init
|
#define xoroshiro128plusplus_init xoroshiro128_init
|
||||||
#define xoroshiro128starstar_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 xoroshiro128plusplus_initFromTime xoroshiro128_initFromTime
|
||||||
#define xoroshiro128starstar_initFromTime xoroshiro128_initFromTime
|
#define xoroshiro128starstar_initFromTime xoroshiro128_initFromTime
|
||||||
|
|
||||||
uint64 xoroshiro128plus_next(xoroshiro128_statePtr);
|
u64 xoroshiro128plus_next(xoroshiro128_statePtr);
|
||||||
uint64 xoroshiro128plusplus_next(xoroshiro128_statePtr);
|
u64 xoroshiro128plusplus_next(xoroshiro128_statePtr);
|
||||||
uint64 xoroshiro128starstar_next(xoroshiro128_statePtr);
|
u64 xoroshiro128starstar_next(xoroshiro128_statePtr);
|
||||||
|
|
||||||
static inline void xoroshiro128_free(xoroshiro128_statePtr state) {
|
static inline void xoroshiro128_free(xoroshiro128_statePtr state) {
|
||||||
free(state);
|
free(state);
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
#include "xoroshiro128.h"
|
#include "xoroshiro128.h"
|
||||||
|
|
||||||
/* This is xoroshiro128+ 1.0, our best and fastest small-state generator
|
/* 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
|
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
|
xoroshiro128++/xoroshiro128**. It passes all tests we are aware of
|
||||||
except for the four lower bits, which might fail linearity tests (and
|
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
|
just those), so if low linear complexity is not considered an issue (as
|
||||||
@@ -32,15 +32,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
better results in our test than the 2016 version (a=55, b=14, c=36).
|
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));
|
return (x << k) | (x >> (64 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 xoroshiro128plus_next(void* _state){
|
u64 xoroshiro128plus_next(void* _state){
|
||||||
xoroshiro128_state* state=_state;
|
xoroshiro128_state* state=_state;
|
||||||
const uint64 s0 = state->s[0];
|
const u64 s0 = state->s[0];
|
||||||
uint64 s1 = state->s[1];
|
u64 s1 = state->s[1];
|
||||||
const uint64 result = s0 + s1;
|
const u64 result = s0 + s1;
|
||||||
|
|
||||||
s1 ^= s0;
|
s1 ^= s0;
|
||||||
state->s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b
|
state->s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b
|
||||||
@@ -49,7 +49,7 @@ uint64 xoroshiro128plus_next(void* _state){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* xoroshiro128_init(uint64 seed){
|
void* xoroshiro128_init(u64 seed){
|
||||||
xoroshiro128_state* state=malloc(sizeof(xoroshiro128_state));
|
xoroshiro128_state* state=malloc(sizeof(xoroshiro128_state));
|
||||||
splitmix64_state* splitmix=splitmix64_init(seed);
|
splitmix64_state* splitmix=splitmix64_init(seed);
|
||||||
state->s[0]=splitmix64_next(splitmix);
|
state->s[0]=splitmix64_next(splitmix);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
tests we are aware of, but its state space is large enough only for
|
tests we are aware of, but its state space is large enough only for
|
||||||
mild parallelism.
|
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).
|
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
|
The state must be seeded so that it is not everywhere zero. If you have
|
||||||
@@ -21,15 +21,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
output to fill s. */
|
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));
|
return (x << k) | (x >> (64 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 xoroshiro128plusplus_next(void* _state){
|
u64 xoroshiro128plusplus_next(void* _state){
|
||||||
xoroshiro128_state* state=_state;
|
xoroshiro128_state* state=_state;
|
||||||
const uint64 s0 = state->s[0];
|
const u64 s0 = state->s[0];
|
||||||
uint64 s1 = state->s[1];
|
u64 s1 = state->s[1];
|
||||||
const uint64 result = rotl(s0 + s1, 17) + s0;
|
const u64 result = rotl(s0 + s1, 17) + s0;
|
||||||
|
|
||||||
s1 ^= s0;
|
s1 ^= s0;
|
||||||
state->s[0] = rotl(s0, 49) ^ s1 ^ (s1 << 21); // a, b
|
state->s[0] = rotl(s0, 49) ^ s1 ^ (s1 << 21); // a, b
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
tests we are aware of, but its state space is large enough only for
|
tests we are aware of, but its state space is large enough only for
|
||||||
mild parallelism.
|
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).
|
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
|
The state must be seeded so that it is not everywhere zero. If you have
|
||||||
@@ -21,15 +21,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
output to fill s. */
|
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));
|
return (x << k) | (x >> (64 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 xoroshiro128starstar_next(void* _state){
|
u64 xoroshiro128starstar_next(void* _state){
|
||||||
xoroshiro128_state* state=_state;
|
xoroshiro128_state* state=_state;
|
||||||
const uint64 s0 = state->s[0];
|
const u64 s0 = state->s[0];
|
||||||
uint64 s1 = state->s[1];
|
u64 s1 = state->s[1];
|
||||||
const uint64 result = rotl(s0 * 5, 7) * 9;
|
const u64 result = rotl(s0 * 5, 7) * 9;
|
||||||
|
|
||||||
s1 ^= s0;
|
s1 ^= s0;
|
||||||
state->s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b
|
state->s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint64 merged[2];
|
u64 merged[2];
|
||||||
uint32 s[4];
|
u32 s[4];
|
||||||
} xoshiro128_state;
|
} xoshiro128_state;
|
||||||
typedef void* xoshiro128_statePtr;
|
typedef void* xoshiro128_statePtr;
|
||||||
|
|
||||||
xoshiro128_statePtr xoshiro128_init(uint64 seed);
|
xoshiro128_statePtr xoshiro128_init(u64 seed);
|
||||||
#define xoshiro128plus_init xoshiro128_init
|
#define xoshiro128plus_init xoshiro128_init
|
||||||
#define xoshiro128plusplus_init xoshiro128_init
|
#define xoshiro128plusplus_init xoshiro128_init
|
||||||
#define xoshiro128starstar_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 xoshiro128plusplus_initFromTime xoshiro128_initFromTime
|
||||||
#define xoshiro128starstar_initFromTime xoshiro128_initFromTime
|
#define xoshiro128starstar_initFromTime xoshiro128_initFromTime
|
||||||
|
|
||||||
uint32 xoshiro128plus_next(xoshiro128_statePtr);
|
u32 xoshiro128plus_next(xoshiro128_statePtr);
|
||||||
uint32 xoshiro128plusplus_next(xoshiro128_statePtr);
|
u32 xoshiro128plusplus_next(xoshiro128_statePtr);
|
||||||
uint32 xoshiro128starstar_next(xoshiro128_statePtr);
|
u32 xoshiro128starstar_next(xoshiro128_statePtr);
|
||||||
|
|
||||||
static inline void xoshiro128_free(xoshiro128_statePtr state) {
|
static inline void xoshiro128_free(xoshiro128_statePtr state) {
|
||||||
free(state);
|
free(state);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
#include "xoshiro128.h"
|
#include "xoshiro128.h"
|
||||||
|
|
||||||
/* This is xoshiro128+ 1.0, our best and fastest 32-bit generator for 32-bit
|
/* 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-poi32 numbers. We suggest to use its upper bits for
|
||||||
floating-point generation, as it is slightly faster than xoshiro128**.
|
floating-poi32 generation, as it is slightly faster than xoshiro128**.
|
||||||
It passes all tests we are aware of except for
|
It passes all tests we are aware of except for
|
||||||
linearity tests, as the lowest four bits have low linear complexity, so
|
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
|
if low linear complexity is not considered an issue (as it is usually
|
||||||
@@ -22,15 +22,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
The state must be seeded so that it is not everywhere zero. */
|
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));
|
return (x << k) | (x >> (32 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 xoshiro128plus_next(void* _state){
|
u32 xoshiro128plus_next(void* _state){
|
||||||
xoshiro128_state* state=_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[2] ^= state->s[0];
|
||||||
state->s[3] ^= state->s[1];
|
state->s[3] ^= state->s[1];
|
||||||
@@ -44,7 +44,7 @@ uint32 xoshiro128plus_next(void* _state){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* xoshiro128_init(uint64 seed){
|
void* xoshiro128_init(u64 seed){
|
||||||
xoshiro128_state* state=malloc(sizeof(xoshiro128_state));
|
xoshiro128_state* state=malloc(sizeof(xoshiro128_state));
|
||||||
splitmix64_state* splitmix=splitmix64_init(seed);
|
splitmix64_state* splitmix=splitmix64_init(seed);
|
||||||
state->merged[0]=splitmix64_next(splitmix);
|
state->merged[0]=splitmix64_next(splitmix);
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
The state must be seeded so that it is not everywhere zero. */
|
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));
|
return (x << k) | (x >> (32 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 xoshiro128plusplus_next(void* _state){
|
u32 xoshiro128plusplus_next(void* _state){
|
||||||
xoshiro128_state* state=_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[2] ^= state->s[0];
|
||||||
state->s[3] ^= state->s[1];
|
state->s[3] ^= state->s[1];
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
The state must be seeded so that it is not everywhere zero. */
|
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));
|
return (x << k) | (x >> (32 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 xoshiro128starstar_next(void* _state){
|
u32 xoshiro128starstar_next(void* _state){
|
||||||
xoshiro128_state* state=_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[2] ^= state->s[0];
|
||||||
state->s[3] ^= state->s[1];
|
state->s[3] ^= state->s[1];
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint64 s[4];
|
u64 s[4];
|
||||||
} xoshiro256_state;
|
} xoshiro256_state;
|
||||||
typedef void* xoshiro256_statePtr;
|
typedef void* xoshiro256_statePtr;
|
||||||
|
|
||||||
xoshiro256_statePtr xoshiro256_init(uint64 seed);
|
xoshiro256_statePtr xoshiro256_init(u64 seed);
|
||||||
#define xoshiro256plus_init xoshiro256_init
|
#define xoshiro256plus_init xoshiro256_init
|
||||||
#define xoshiro256plusplus_init xoshiro256_init
|
#define xoshiro256plusplus_init xoshiro256_init
|
||||||
#define xoshiro256starstar_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 xoshiro256plusplus_initFromTime xoshiro256_initFromTime
|
||||||
#define xoshiro256starstar_initFromTime xoshiro256_initFromTime
|
#define xoshiro256starstar_initFromTime xoshiro256_initFromTime
|
||||||
|
|
||||||
uint64 xoshiro256plus_next(xoshiro256_statePtr);
|
u64 xoshiro256plus_next(xoshiro256_statePtr);
|
||||||
uint64 xoshiro256plusplus_next(xoshiro256_statePtr);
|
u64 xoshiro256plusplus_next(xoshiro256_statePtr);
|
||||||
uint64 xoshiro256starstar_next(xoshiro256_statePtr);
|
u64 xoshiro256starstar_next(xoshiro256_statePtr);
|
||||||
|
|
||||||
static inline void xoshiro256_free(xoshiro256_statePtr state) {
|
static inline void xoshiro256_free(xoshiro256_statePtr state) {
|
||||||
free(state);
|
free(state);
|
||||||
|
|||||||
@@ -24,15 +24,15 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
output to fill s. */
|
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));
|
return (x << k) | (x >> (64 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 xoshiro256plus_next(void* _state){
|
u64 xoshiro256plus_next(void* _state){
|
||||||
xoshiro256_state* state=_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[2] ^= state->s[0];
|
||||||
state->s[3] ^= state->s[1];
|
state->s[3] ^= state->s[1];
|
||||||
@@ -46,7 +46,7 @@ uint64 xoshiro256plus_next(void* _state){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* xoshiro256_init(uint64 seed){
|
void* xoshiro256_init(u64 seed){
|
||||||
xoshiro256_state* state=malloc(sizeof(xoshiro256_state));
|
xoshiro256_state* state=malloc(sizeof(xoshiro256_state));
|
||||||
splitmix64_state* splitmix=splitmix64_init(seed);
|
splitmix64_state* splitmix=splitmix64_init(seed);
|
||||||
state->s[0]=splitmix64_next(splitmix);
|
state->s[0]=splitmix64_next(splitmix);
|
||||||
|
|||||||
@@ -13,20 +13,20 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
enough for any parallel application, and it passes all tests we are
|
enough for any parallel application, and it passes all tests we are
|
||||||
aware of.
|
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
|
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
|
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
|
||||||
output to fill s. */
|
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));
|
return (x << k) | (x>>(64 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 xoshiro256plusplus_next(void* _state) {
|
u64 xoshiro256plusplus_next(void* _state) {
|
||||||
xoshiro256_state* state=_state;
|
xoshiro256_state* state=_state;
|
||||||
const uint64 result=rotl(state->s[0] + state->s[3], 23) + state->s[0];
|
const u64 result=rotl(state->s[0] + state->s[3], 23) + state->s[0];
|
||||||
const uint64 t=state->s[1] << 17;
|
const u64 t=state->s[1] << 17;
|
||||||
state->s[2] ^= state->s[0];
|
state->s[2] ^= state->s[0];
|
||||||
state->s[3] ^= state->s[1];
|
state->s[3] ^= state->s[1];
|
||||||
state->s[1] ^= state->s[2];
|
state->s[1] ^= state->s[2];
|
||||||
|
|||||||
@@ -13,21 +13,21 @@ See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
|||||||
large enough for any parallel application, and it passes all tests we
|
large enough for any parallel application, and it passes all tests we
|
||||||
are aware of.
|
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
|
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
|
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
|
||||||
output to fill s. */
|
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));
|
return (x << k) | (x >> (64 - k));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 xoshiro256starstar_next(void* _state){
|
u64 xoshiro256starstar_next(void* _state){
|
||||||
xoshiro256_state* state=_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[2] ^= state->s[0];
|
||||||
state->s[3] ^= state->s[1];
|
state->s[3] ^= state->s[1];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
|
||||||
int main(){
|
i32 main(){
|
||||||
if(!setlocale(LC_ALL, "C.UTF8"))
|
if(!setlocale(LC_ALL, "C.UTF8"))
|
||||||
kprintf("\e[93msetlocale failed\n");
|
kprintf("\e[93msetlocale failed\n");
|
||||||
ktDescriptors_beginInit();
|
ktDescriptors_beginInit();
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
#include "../src/Autoarr/Autoarr.h"
|
#include "../src/Autoarr/Autoarr.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
|
i64 _autoarrVsVector(u16 blockCount, u16 blockLength){
|
||||||
uint32 count=blockLength*blockCount;
|
u32 count=blockLength*blockCount;
|
||||||
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
|
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (u64)count);
|
||||||
Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength);
|
Autoarr_i64* ar=Autoarr_create(i64, blockCount, blockLength);
|
||||||
std::vector<int64> vec=std::vector<int64>();
|
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));
|
||||||
optime("vector_push_back", count,
|
optime("vector_push_back", count,
|
||||||
vec.push_back(op_i));
|
vec.push_back(op_i));
|
||||||
int64 t=0;
|
i64 t=0;
|
||||||
optime("Autoarr_get", count,
|
optime("Autoarr_get", count,
|
||||||
t=Autoarr_get(ar, op_i));
|
t=Autoarr_get(ar, op_i));
|
||||||
optime("vector_get", count,
|
optime("vector_get", count,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "../src/Autoarr/Autoarr.h"
|
#include "../src/Autoarr/Autoarr.h"
|
||||||
|
|
||||||
static void printautoarr(Autoarr(uint16)* ar){
|
static void printautoarr(Autoarr(u16)* ar){
|
||||||
kprintf("\e[94mAutoarr(uint16): "
|
kprintf("\e[94mAutoarr(u16): "
|
||||||
IFWIN("%llu", "%lu")
|
IFWIN("%llu", "%lu")
|
||||||
"\n max_blocks_count: %u\n"
|
"\n max_blocks_count: %u\n"
|
||||||
" blocks_count: %u\n"
|
" blocks_count: %u\n"
|
||||||
@@ -10,7 +10,7 @@ static void printautoarr(Autoarr(uint16)* ar){
|
|||||||
" block_length: %u\n"
|
" block_length: %u\n"
|
||||||
" max_length: %u\n"
|
" max_length: %u\n"
|
||||||
" length: %u\n",
|
" length: %u\n",
|
||||||
sizeof(Autoarr(uint16)),
|
sizeof(Autoarr(u16)),
|
||||||
ar->max_blocks_count,
|
ar->max_blocks_count,
|
||||||
ar->blocks_count,
|
ar->blocks_count,
|
||||||
ar->max_block_length,
|
ar->max_block_length,
|
||||||
@@ -19,18 +19,18 @@ static void printautoarr(Autoarr(uint16)* ar){
|
|||||||
Autoarr_length(ar));
|
Autoarr_length(ar));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillar(Autoarr(uint16)* ar){
|
static void fillar(Autoarr(u16)* ar){
|
||||||
for (uint16 i=0;i<Autoarr_max_length(ar);i++)
|
for (u16 i=0;i<Autoarr_max_length(ar);i++)
|
||||||
Autoarr_add(ar,i);
|
Autoarr_add(ar,i);
|
||||||
}
|
}
|
||||||
static void resetar(Autoarr(uint16)* ar){
|
static void resetar(Autoarr(u16)* ar){
|
||||||
for (uint16 i=0;i<Autoarr_max_length(ar);i++)
|
for (u16 i=0;i<Autoarr_max_length(ar);i++)
|
||||||
Autoarr_set(ar,i,Autoarr_max_length(ar)-i-1);
|
Autoarr_set(ar,i,Autoarr_max_length(ar)-i-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printallval(Autoarr(uint16)* ar){
|
static void printallval(Autoarr(u16)* ar){
|
||||||
kprintf("\e[90m");
|
kprintf("\e[90m");
|
||||||
for (uint16 i=0;i<Autoarr_length(ar);i++)
|
for (u16 i=0;i<Autoarr_length(ar);i++)
|
||||||
kprintf("%u ",Autoarr_get(ar,i));
|
kprintf("%u ",Autoarr_get(ar,i));
|
||||||
kprintf("\n");
|
kprintf("\n");
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ static void printallval(Autoarr(uint16)* ar){
|
|||||||
void test_autoarr(){
|
void test_autoarr(){
|
||||||
optime("test_autoarr",1,({
|
optime("test_autoarr",1,({
|
||||||
kprintf("\e[96m------------[test_autoarr]------------\n");
|
kprintf("\e[96m------------[test_autoarr]------------\n");
|
||||||
Autoarr(uint16)* ar=Autoarr_create(uint16,10,16);
|
Autoarr(u16)* ar=Autoarr_create(u16,10,16);
|
||||||
kprintf("\e[92mautoarr created\n");
|
kprintf("\e[92mautoarr created\n");
|
||||||
fillar(ar);
|
fillar(ar);
|
||||||
kprintf("\e[92mautoarr filled up\n");
|
kprintf("\e[92mautoarr filled up\n");
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ const char text[]=
|
|||||||
"message: {\n"
|
"message: {\n"
|
||||||
" bool: false;"
|
" bool: false;"
|
||||||
" int: -2515;"
|
" int: -2515;"
|
||||||
" uint:#comment!\n 0u;"
|
" u:#comment!\n 0u;"
|
||||||
" double: 965.557f;#another comment!\n"
|
" f64: 965.557f;#another comment!\n"
|
||||||
" text: \"_$\\\"\\\\'''a ыыы000;2;=:%d;```\";\n"
|
" text: \"_$\\\"\\\\'''a ыыы000;2;=:%d;```\";\n"
|
||||||
" list: [10,20,30,0,0 ];"
|
" list: [10,20,30,0,0 ];"
|
||||||
"};"
|
"};"
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ char data[]="iojihiojopijiugbjmoihftytryfdrh";
|
|||||||
kprintf("\e[94mfunction: \e[92m" #hashf "\n");\
|
kprintf("\e[94mfunction: \e[92m" #hashf "\n");\
|
||||||
hasht h=0;\
|
hasht h=0;\
|
||||||
optime("speed test", 1, ({\
|
optime("speed test", 1, ({\
|
||||||
for(uint32 i=0; i<SPEED_TESTS; i++)\
|
for(u32 i=0; i<SPEED_TESTS; i++)\
|
||||||
h=hashf(h, data, sizeof(data));\
|
h=hashf(h, data, sizeof(data));\
|
||||||
}));\
|
}));\
|
||||||
/*kprintf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/\
|
/*kprintf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/\
|
||||||
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
|
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
|
||||||
optime("collision test",1,({\
|
optime("collision test",1,({\
|
||||||
uint32 collisions=0;\
|
u32 collisions=0;\
|
||||||
for(uint64 i=0;i< COLLISION_TESTS;i++){\
|
for(u64 i=0;i< COLLISION_TESTS;i++){\
|
||||||
hasht h=hashb(hashf, (uint8*)&i, sizeof(i));\
|
hasht h=hashb(hashf, (u8*)&i, sizeof(i));\
|
||||||
bool col=false;\
|
bool col=false;\
|
||||||
Autoarr_foreach(hashes,e,({\
|
Autoarr_foreach(hashes,e,({\
|
||||||
if(e==h) {\
|
if(e==h) {\
|
||||||
@@ -40,7 +40,7 @@ char data[]="iojihiojopijiugbjmoihftytryfdrh";
|
|||||||
void test_hash_functions(){
|
void test_hash_functions(){
|
||||||
optime("test_hash_functions",1,({
|
optime("test_hash_functions",1,({
|
||||||
kprintf("\e[96m--------[test_hash_functions]---------\n");
|
kprintf("\e[96m--------[test_hash_functions]---------\n");
|
||||||
test_hashfunc(uint32, hash_crc32);
|
test_hashfunc(u32, hash_crc32);
|
||||||
test_hashfunc(uint32, hash_sdbm32);
|
test_hashfunc(u32, hash_sdbm32);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -15,16 +15,16 @@ void print_hashtable(Hashtable* ht){
|
|||||||
|
|
||||||
void printrowgraph(Hashtable* ht){
|
void printrowgraph(Hashtable* ht){
|
||||||
kprintf("\e[94mrow length graph:\n");
|
kprintf("\e[94mrow length graph:\n");
|
||||||
uint16 lgs_l=1000;
|
u16 lgs_l=1000;
|
||||||
uint32 lgs[lgs_l];
|
u32 lgs[lgs_l];
|
||||||
for(uint32 i=0; i<lgs_l; i++)
|
for(u32 i=0; i<lgs_l; i++)
|
||||||
lgs[i]=0;
|
lgs[i]=0;
|
||||||
for(uint16 h=0;h<Hashtable_height(ht);h++){
|
for(u16 h=0;h<Hashtable_height(ht);h++){
|
||||||
Autoarr(KVPair)* ar=ht->rows[h];
|
Autoarr(KVPair)* ar=ht->rows[h];
|
||||||
uint32 l=Autoarr_length(ar);
|
u32 l=Autoarr_length(ar);
|
||||||
lgs[l]++;
|
lgs[l]++;
|
||||||
}
|
}
|
||||||
for(uint32 i=0; i<lgs_l; i++)
|
for(u32 i=0; i<lgs_l; i++)
|
||||||
if(lgs[i]>0) {
|
if(lgs[i]>0) {
|
||||||
char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2));
|
char* str0=char_multiply(' ',i>=100?0:(i>=10?1:2));
|
||||||
char* str1=char_multiply(' ',lgs[i]>=100?0:(lgs[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);
|
char* key=malloc(12);
|
||||||
IFMSC(
|
IFMSC(
|
||||||
sprintf_s(key,12,"key_%u",i),
|
sprintf_s(key,12,"key_%u",i),
|
||||||
@@ -46,13 +46,13 @@ char* genkey(uint32 i){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fill(Hashtable* ht){
|
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));
|
Hashtable_add(ht,genkey(i),UniUInt64(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
Unitype gett(Hashtable* ht){
|
Unitype gett(Hashtable* ht){
|
||||||
Unitype u;
|
Unitype u;
|
||||||
for(uint32 i=0;i<100000;i++){
|
for(u32 i=0;i<100000;i++){
|
||||||
char* key=genkey(i);
|
char* key=genkey(i);
|
||||||
u=Hashtable_get(ht,key);
|
u=Hashtable_get(ht,key);
|
||||||
free(key);
|
free(key);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ void test_kprint(){
|
|||||||
//int
|
//int
|
||||||
kprint(kp_fgCyan|
|
kprint(kp_fgCyan|
|
||||||
kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n");
|
kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n");
|
||||||
//uint
|
//u
|
||||||
kprint(kp_fgGreen|
|
kprint(kp_fgGreen|
|
||||||
kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ',
|
kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ',
|
||||||
kp_u,1234567890987654321LL, kp_c,'\n');
|
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,-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,0.000020004f, kp_c,' ',
|
||||||
kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n');
|
kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n');
|
||||||
//double
|
//f64
|
||||||
kprint(kp_fgYellowD|
|
kprint(kp_fgYellowD|
|
||||||
kp_f,-4000.0109, kp_c,' ', kp_f,-0.000020004, kp_c,'\n',
|
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',
|
kp_f,-1.0, kp_c,' ', kp_f,0.0, kp_c,' ', kp_f,1.0, kp_c,'\n',
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ void test_kprint_colors(){
|
|||||||
/* IFWIN(
|
/* IFWIN(
|
||||||
({
|
({
|
||||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
for(uint8 col=0; col<255; col++){
|
for(u8 col=0; col<255; col++){
|
||||||
SetConsoleTextAttribute(hConsole, col);
|
SetConsoleTextAttribute(hConsole, col);
|
||||||
kprintf("%u ",col);
|
kprintf("%u ",col);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
({
|
({
|
||||||
for(uint8 col=0; col<255; col++)
|
for(u8 col=0; col<255; col++)
|
||||||
kprintf("\e[%um%u ", col, col);
|
kprintf("\e[%um%u ", col, col);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,18 +5,18 @@
|
|||||||
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){\
|
#define test_alg(ALG, VALUE_SIZE, EXPECTED_FROM_ZERO){\
|
||||||
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n");\
|
kprintf("\e[94mrng algorithm: \e[96m" #ALG "\n");\
|
||||||
void* s= ALG##_init(0);\
|
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:");\
|
kprintf("\e[97m next from zero seed:");\
|
||||||
if(r!=EXPECTED_FROM_ZERO){\
|
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);\
|
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);\
|
ALG##_free(s);\
|
||||||
s= ALG##_initFromTime();\
|
s= ALG##_initFromTime();\
|
||||||
r=ALG##_next(s);\
|
r=ALG##_next(s);\
|
||||||
ALG##_free(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(){
|
void test_rng_algorithms(){
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ void printstnode(STNode* node){
|
|||||||
kprintf("\n");
|
kprintf("\n");
|
||||||
// prints pointers to all existing branches
|
// prints pointers to all existing branches
|
||||||
/* kprintf(" branches: %p\n", node->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]);
|
kprintf(" \e[90m[%u]=%p\n",i,node->branches[i]);
|
||||||
if(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]);
|
kprintf(" \e[90m[%u]=%p\n",ii,node->branches[i][ii]);
|
||||||
if(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]);
|
kprintf(" \e[90m[%u]=%p\n",iii,node->branches[i][ii][iii]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user