exported Autoarr_KVPair & Autoarr_Unitype

This commit is contained in:
Timerix22 2022-03-31 00:09:24 +03:00
parent c1d004f411
commit 3940eeb2a7
13 changed files with 133 additions and 28 deletions

View File

@ -7,20 +7,20 @@ extern "C" {
#include "Autoarr_declare.h" #include "Autoarr_declare.h"
#include "Autoarr_define.h" #include "Autoarr_define.h"
declare_Autoarr(uint8) declare_Autoarr(uint8)
declare_Autoarr(int8) declare_Autoarr(int8)
declare_Autoarr(uint16) declare_Autoarr(uint16)
declare_Autoarr(int16) declare_Autoarr(int16)
declare_Autoarr(uint32) declare_Autoarr(uint32)
declare_Autoarr(int32) declare_Autoarr(int32)
declare_Autoarr(uint64) declare_Autoarr(uint64)
declare_Autoarr(int64) declare_Autoarr(int64)
declare_Autoarr(float) declare_Autoarr(float)
declare_Autoarr(double) declare_Autoarr(double)
declare_Autoarr(Unitype) declare_Autoarr(Unitype)
//right func to clear array of unitype values //right func to clear array of unitype values
void Autoarr_Unitype_clear(Autoarr(Unitype)* ar); void Autoarr_Unitype_clear(Autoarr(Unitype)* ar);
#define Autoarr_foreach(ar,elem,codeblock)({\ #define Autoarr_foreach(ar,elem,codeblock)({\
if(ar->blocks_count>0) {\ if(ar->blocks_count>0) {\

View File

@ -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

View File

@ -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

View File

@ -25,3 +25,8 @@ bool DtsodV24_remove(Hashtable* dtsod, char* key){
*val=UniNull; *val=UniNull;
return true; return true;
} }
//frees memory including memory of elements (hashtables, autoarrs, etc.)
void DtsodV24_free(Hashtable* dtsod){
Hashtable_free(dtsod);
}

View File

@ -24,6 +24,9 @@ bool DtsodV24_contains(Hashtable* dtsod, char* key);
//replaces value with UniNull if key exists in dtsod //replaces value with UniNull if key exists in dtsod
bool DtsodV24_remove(Hashtable* dtsod, char* key); bool DtsodV24_remove(Hashtable* dtsod, char* key);
//frees memory including memory of elements (hashtables, autoarrs, etc.)
void DtsodV24_free(Hashtable* dtsod);
#if __cplusplus #if __cplusplus
} }
#endif #endif

View File

@ -151,7 +151,7 @@ Unitype __ParseValue(DeserializeSharedData* shared, string str){
switch(str.ptr[str.length-1]){ switch(str.ptr[str.length-1]){
case 'f': { case 'f': {
char* _c=string_cpToCptr(str); char* _c=string_cpToCptr(str);
Unitype rez=Uni(Double,strtod(_c,NULL)); Unitype rez=Uni(Float64,strtod(_c,NULL));
free(_c); free(_c);
return rez; return rez;
} }

View File

@ -25,7 +25,7 @@ EXPORT void CALL kerep_DtsodV24_get(Hashtable* dtsod, char* key, Unitype* output
*output=DtsodV24_get(dtsod, key); *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){ EXPORT void CALL kerep_DtsodV24_addOrSet(Hashtable* dtsod, char* key, Unitype value){
DtsodV24_addOrSet(dtsod, key, 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); *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 #if __cplusplus
} }
#endif #endif

View File

@ -34,8 +34,8 @@ void __AppendValue(SerializeSharedData* shared, Unitype u){
StringBuilder_append_uint64(b,u.UInt64); StringBuilder_append_uint64(b,u.UInt64);
addc('u'); addc('u');
break; break;
case Double: case Float64:
StringBuilder_append_double(b,u.Double); StringBuilder_append_double(b,u.Float64);
addc('f'); addc('f');
break; break;
case CharPtr: case CharPtr:

View File

@ -25,7 +25,7 @@ void Hashtable_free(Hashtable* ht){
free(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){ void Hashtable_expand(Hashtable* ht){

View File

@ -23,7 +23,10 @@ uint32 Hashtable_height(Hashtable* ht);
//use cptr_copy() to create new string if needed //use cptr_copy() to create new string if needed
#define KVPair(key,value) (KeyValuePair){key,value} #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_pair(Hashtable* ht, KeyValuePair p);
void Hashtable_add(Hashtable* ht, char* key, Unitype u); void Hashtable_add(Hashtable* ht, char* key, Unitype u);

View File

@ -7,8 +7,8 @@
const char* my_type_name(my_type t){ const char* my_type_name(my_type t){
switch (t) { switch (t) {
case Null: return "Null"; case Null: return "Null";
case Double: return "Double"; case Float64: return "Float64";
case Float: return "Float"; case Float32: return "Float32";
case Bool: return "Bool"; case Bool: return "Bool";
case Char: return "Char"; case Char: return "Char";
case Int8: return "Int8"; case Int8: return "Int8";
@ -49,8 +49,8 @@ const char* my_type_name(my_type t){
void Unitype_free(Unitype u){ void Unitype_free(Unitype u){
switch (u.type) { switch (u.type) {
case Null: case Null:
case Float: case Float32:
case Double: case Float64:
case Char: case Char:
case Bool: case Bool:
case Int8: case Int8:
@ -119,7 +119,7 @@ void Unitype_free(Unitype u){
void printuni(Unitype v){ void printuni(Unitype v){
switch (v.type) { switch (v.type) {
case Null: printf("{Null}");break; 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 Char: printf("{%s : '%c'}",my_type_name(v.type),v.Char);break;
case Bool: case Bool:
case UInt64: printf("{%s : %lu}",my_type_name(v.type),v.UInt64);break; case UInt64: printf("{%s : %lu}",my_type_name(v.type),v.UInt64);break;

View File

@ -14,8 +14,10 @@ typedef int32_t int32;
typedef uint32_t uint32; typedef uint32_t uint32;
typedef int64_t int64; typedef int64_t int64;
typedef uint64_t uint64; typedef uint64_t uint64;
typedef float float32;
typedef double float64;
typedef enum __attribute__((__packed__)) my_type { typedef enum __attribute__((__packed__)) my_type {
Null, Float, Double, Char, Bool, Null, Float32, Float64, Char, Bool,
UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64,
UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr, UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr,
CharPtr, STNodePtr, HashtablePtr, CharPtr, STNodePtr, HashtablePtr,
@ -31,7 +33,7 @@ typedef struct Unitype{
union { union {
int64 Int64; int64 Int64;
uint64 UInt64; uint64 UInt64;
double Double; double Float64;
char Char; char Char;
bool Bool; bool Bool;
void* VoidPtr; void* VoidPtr;

View File

@ -35,7 +35,7 @@ void test_searchtree(){
printuni(u); printuni(u);
ST_push(node,"time", u); ST_push(node,"time", u);
printf(" -> time\n "); printf(" -> time\n ");
u=(Unitype){.type=Double,.Double=-542.00600}; u=(Unitype){.type=Float64,.Float64=-542.00600};
printuni(u); printuni(u);
ST_push(node,"author_id", u); ST_push(node,"author_id", u);
printf(" -> author_id\n "); printf(" -> author_id\n ");
@ -43,7 +43,7 @@ void test_searchtree(){
printuni(u); printuni(u);
ST_push(node,"channel_id", u); ST_push(node,"channel_id", u);
printf(" -> channel_id\n "); printf(" -> channel_id\n ");
u=(Unitype){.type=Double,.Double=32.2004}; u=(Unitype){.type=Float64,.Float64=32.2004};
printuni(u); printuni(u);
ST_push(node,"message_id", u); ST_push(node,"message_id", u);
printf(" -> message_id\n "); printf(" -> message_id\n ");