diff --git a/Autoarr/Autoarr.h b/Autoarr/Autoarr.h index 9589db9..5f12633 100644 --- a/Autoarr/Autoarr.h +++ b/Autoarr/Autoarr.h @@ -7,20 +7,20 @@ extern "C" { #include "Autoarr_declare.h" #include "Autoarr_define.h" - declare_Autoarr(uint8) - declare_Autoarr(int8) - declare_Autoarr(uint16) - declare_Autoarr(int16) - declare_Autoarr(uint32) - declare_Autoarr(int32) - declare_Autoarr(uint64) - declare_Autoarr(int64) - declare_Autoarr(float) - declare_Autoarr(double) - declare_Autoarr(Unitype) +declare_Autoarr(uint8) +declare_Autoarr(int8) +declare_Autoarr(uint16) +declare_Autoarr(int16) +declare_Autoarr(uint32) +declare_Autoarr(int32) +declare_Autoarr(uint64) +declare_Autoarr(int64) +declare_Autoarr(float) +declare_Autoarr(double) +declare_Autoarr(Unitype) - //right func to clear array of unitype values - void Autoarr_Unitype_clear(Autoarr(Unitype)* ar); +//right func to clear array of unitype values +void Autoarr_Unitype_clear(Autoarr(Unitype)* ar); #define Autoarr_foreach(ar,elem,codeblock)({\ if(ar->blocks_count>0) {\ diff --git a/Autoarr/Autoarr_KVPair_exported.c b/Autoarr/Autoarr_KVPair_exported.c new file mode 100644 index 0000000..51d161d --- /dev/null +++ b/Autoarr/Autoarr_KVPair_exported.c @@ -0,0 +1,40 @@ +#if __cplusplus +extern "C" { +#endif + +#include "Autoarr.h" +#include "../Hashtable/KeyValuePair.h" + +EXPORT void CALL kerep_Autoarr_KeyValuePair_create(uint16 max_blocks_count, uint16 max_block_length, Autoarr_KeyValuePair** output){ + *output=malloc(sizeof(Autoarr_KeyValuePair)); + **output=Autoarr_create(KeyValuePair, max_blocks_count, max_block_length); +} + +EXPORT void CALL kerep_Autoarr_KeyValuePair_free(Autoarr_KeyValuePair* ar){ + Autoarr_clear(ar); + free(ar); +} + +EXPORT void CALL kerep_Autoarr_KeyValuePair_get(Autoarr_KeyValuePair* ar, uint32 index, KeyValuePair* output){ + *output=Autoarr_get(ar, index); +} + +EXPORT void CALL kerep_Autoarr_KeyValuePair_add(Autoarr_KeyValuePair* ar, KeyValuePair element){ + Autoarr_add(ar, element); +} + +EXPORT void CALL kerep_Autoarr_KeyValuePair_set(Autoarr_KeyValuePair* ar, uint32 index, KeyValuePair element){ + Autoarr_set(ar, index, element); +} + +EXPORT void CALL kerep_Autoarr_KeyValuePair_length(Autoarr_KeyValuePair* ar, uint32* output){ + *output=Autoarr_length(ar); +} + +EXPORT void CALL kerep_Autoarr_KeyValuePair_max_length(Autoarr_KeyValuePair* ar, uint32* output){ + *output=Autoarr_max_length(ar); +} + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/Autoarr/Autoarr_Unitype_exported.c b/Autoarr/Autoarr_Unitype_exported.c new file mode 100644 index 0000000..dddb259 --- /dev/null +++ b/Autoarr/Autoarr_Unitype_exported.c @@ -0,0 +1,39 @@ +#if __cplusplus +extern "C" { +#endif + +#include "Autoarr.h" + +EXPORT void CALL kerep_Autoarr_Unitype_create(uint16 max_blocks_count, uint16 max_block_length, Autoarr_Unitype** output){ + *output=malloc(sizeof(Autoarr_Unitype)); + **output=Autoarr_create(Unitype, max_blocks_count, max_block_length); +} + +EXPORT void CALL kerep_Autoarr_Unitype_free(Autoarr_Unitype* ar){ + Autoarr_clear(ar); + free(ar); +} + +EXPORT void CALL kerep_Autoarr_Unitype_get(Autoarr_Unitype* ar, uint32 index, Unitype* output){ + *output=Autoarr_get(ar, index); +} + +EXPORT void CALL kerep_Autoarr_Unitype_add(Autoarr_Unitype* ar, Unitype element){ + Autoarr_add(ar, element); +} + +EXPORT void CALL kerep_Autoarr_Unitype_set(Autoarr_Unitype* ar, uint32 index, Unitype element){ + Autoarr_set(ar, index, element); +} + +EXPORT void CALL kerep_Autoarr_Unitype_length(Autoarr_Unitype* ar, uint32* output){ + *output=Autoarr_length(ar); +} + +EXPORT void CALL kerep_Autoarr_Unitype_max_length(Autoarr_Unitype* ar, uint32* output){ + *output=Autoarr_max_length(ar); +} + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/DtsodParser/DtsodV24.c b/DtsodParser/DtsodV24.c index bf8cbf2..21b0984 100644 --- a/DtsodParser/DtsodV24.c +++ b/DtsodParser/DtsodV24.c @@ -25,3 +25,8 @@ bool DtsodV24_remove(Hashtable* dtsod, char* key){ *val=UniNull; return true; } + +//frees memory including memory of elements (hashtables, autoarrs, etc.) +void DtsodV24_free(Hashtable* dtsod){ + Hashtable_free(dtsod); +} \ No newline at end of file diff --git a/DtsodParser/DtsodV24.h b/DtsodParser/DtsodV24.h index 5b0fa6c..cf0c090 100644 --- a/DtsodParser/DtsodV24.h +++ b/DtsodParser/DtsodV24.h @@ -24,6 +24,9 @@ bool DtsodV24_contains(Hashtable* dtsod, char* key); //replaces value with UniNull if key exists in dtsod bool DtsodV24_remove(Hashtable* dtsod, char* key); +//frees memory including memory of elements (hashtables, autoarrs, etc.) +void DtsodV24_free(Hashtable* dtsod); + #if __cplusplus } #endif \ No newline at end of file diff --git a/DtsodParser/DtsodV24_deserialize.c b/DtsodParser/DtsodV24_deserialize.c index ee8d3a5..adedb24 100644 --- a/DtsodParser/DtsodV24_deserialize.c +++ b/DtsodParser/DtsodV24_deserialize.c @@ -151,7 +151,7 @@ Unitype __ParseValue(DeserializeSharedData* shared, string str){ switch(str.ptr[str.length-1]){ case 'f': { char* _c=string_cpToCptr(str); - Unitype rez=Uni(Double,strtod(_c,NULL)); + Unitype rez=Uni(Float64,strtod(_c,NULL)); free(_c); return rez; } diff --git a/DtsodParser/DtsodV24_exported.c b/DtsodParser/DtsodV24_exported.c index b1867ae..3ea291f 100644 --- a/DtsodParser/DtsodV24_exported.c +++ b/DtsodParser/DtsodV24_exported.c @@ -25,7 +25,7 @@ EXPORT void CALL kerep_DtsodV24_get(Hashtable* dtsod, char* key, Unitype* output *output=DtsodV24_get(dtsod, key); } -//adds or sets value +//adds or sets the value EXPORT void CALL kerep_DtsodV24_addOrSet(Hashtable* dtsod, char* key, Unitype value){ DtsodV24_addOrSet(dtsod, key, value); } @@ -40,6 +40,19 @@ EXPORT void CALL kerep_DtsodV24_remove(Hashtable* dtsod, char* key, bool* output *output=DtsodV24_remove(dtsod, key); } +//replaces value with UniNull if key exists in dtsod +EXPORT void CALL kerep_DtsodV24_free(Hashtable* dtsod){ + DtsodV24_free(dtsod); +} + +EXPORT void CALL kerep_DtsodV24_height(Hashtable* dtsod, uint16* heigth){ + *heigth=Hashtable_height(dtsod); +} + +EXPORT void CALL kerep_DtsodV24_getrow(Hashtable* dtsod, uint16 h, Autoarr_KeyValuePair** row){ + *row=dtsod->rows+h; +} + #if __cplusplus } #endif \ No newline at end of file diff --git a/DtsodParser/DtsodV24_serialize.c b/DtsodParser/DtsodV24_serialize.c index b2bb9f9..3f4937c 100644 --- a/DtsodParser/DtsodV24_serialize.c +++ b/DtsodParser/DtsodV24_serialize.c @@ -34,8 +34,8 @@ void __AppendValue(SerializeSharedData* shared, Unitype u){ StringBuilder_append_uint64(b,u.UInt64); addc('u'); break; - case Double: - StringBuilder_append_double(b,u.Double); + case Float64: + StringBuilder_append_double(b,u.Float64); addc('f'); break; case CharPtr: diff --git a/Hashtable/Hashtable.c b/Hashtable/Hashtable.c index 393d0e8..9f66450 100644 --- a/Hashtable/Hashtable.c +++ b/Hashtable/Hashtable.c @@ -25,7 +25,7 @@ void Hashtable_free(Hashtable* ht){ free(ht); } -uint32 Hashtable_height(Hashtable* ht){ return HT_HEIGHTS[ht->hein]; } +uint32 Hashtable_height(Hashtable* ht) { return HT_HEIGHTS[ht->hein]; } void Hashtable_expand(Hashtable* ht){ diff --git a/Hashtable/Hashtable.h b/Hashtable/Hashtable.h index 379b30a..14714de 100644 --- a/Hashtable/Hashtable.h +++ b/Hashtable/Hashtable.h @@ -23,7 +23,10 @@ uint32 Hashtable_height(Hashtable* ht); //use cptr_copy() to create new string if needed #define KVPair(key,value) (KeyValuePair){key,value} - +// +// don't add pairs with the same keys, +// or something weird will happen +// void Hashtable_add_pair(Hashtable* ht, KeyValuePair p); void Hashtable_add(Hashtable* ht, char* key, Unitype u); diff --git a/base/types.c b/base/types.c index b4f6ba1..8aa92fe 100644 --- a/base/types.c +++ b/base/types.c @@ -7,8 +7,8 @@ const char* my_type_name(my_type t){ switch (t) { case Null: return "Null"; - case Double: return "Double"; - case Float: return "Float"; + case Float64: return "Float64"; + case Float32: return "Float32"; case Bool: return "Bool"; case Char: return "Char"; case Int8: return "Int8"; @@ -49,8 +49,8 @@ const char* my_type_name(my_type t){ void Unitype_free(Unitype u){ switch (u.type) { case Null: - case Float: - case Double: + case Float32: + case Float64: case Char: case Bool: case Int8: @@ -119,7 +119,7 @@ void Unitype_free(Unitype u){ void printuni(Unitype v){ switch (v.type) { case Null: printf("{Null}");break; - case Double: printf("{%s : %lf}",my_type_name(v.type),v.Double);break; + case Float64: printf("{%s : %lf}",my_type_name(v.type),v.Float64);break; case Char: printf("{%s : '%c'}",my_type_name(v.type),v.Char);break; case Bool: case UInt64: printf("{%s : %lu}",my_type_name(v.type),v.UInt64);break; diff --git a/base/types.h b/base/types.h index 7956931..af08c82 100644 --- a/base/types.h +++ b/base/types.h @@ -14,8 +14,10 @@ typedef int32_t int32; typedef uint32_t uint32; typedef int64_t int64; typedef uint64_t uint64; +typedef float float32; +typedef double float64; typedef enum __attribute__((__packed__)) my_type { - Null, Float, Double, Char, Bool, + Null, Float32, Float64, Char, Bool, UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr, CharPtr, STNodePtr, HashtablePtr, @@ -31,7 +33,7 @@ typedef struct Unitype{ union { int64 Int64; uint64 UInt64; - double Double; + double Float64; char Char; bool Bool; void* VoidPtr; diff --git a/tests/test_searchtree.c b/tests/test_searchtree.c index 1dc4ce3..a94bb06 100644 --- a/tests/test_searchtree.c +++ b/tests/test_searchtree.c @@ -35,7 +35,7 @@ void test_searchtree(){ printuni(u); ST_push(node,"time", u); printf(" -> time\n "); - u=(Unitype){.type=Double,.Double=-542.00600}; + u=(Unitype){.type=Float64,.Float64=-542.00600}; printuni(u); ST_push(node,"author_id", u); printf(" -> author_id\n "); @@ -43,7 +43,7 @@ void test_searchtree(){ printuni(u); ST_push(node,"channel_id", u); printf(" -> channel_id\n "); - u=(Unitype){.type=Double,.Double=32.2004}; + u=(Unitype){.type=Float64,.Float64=32.2004}; printuni(u); ST_push(node,"message_id", u); printf(" -> message_id\n ");