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

@ -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;
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
bool DtsodV24_remove(Hashtable* dtsod, char* key);
//frees memory including memory of elements (hashtables, autoarrs, etc.)
void DtsodV24_free(Hashtable* dtsod);
#if __cplusplus
}
#endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 ");