diff --git a/.gitignore b/.gitignore
index 3cf06f0..6e5b49f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,13 +2,12 @@
bin/
obj/
-# IDE files
+# user files
+.old*/
.vs/
.vscode/
.vshistory/
-.idea/
.editorconfig
*.user
-
-#backups
-.old*/
+*.vcxproj.filters
+.config
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..1c2fda5
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..df5f35d
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/customTargets.xml b/.idea/customTargets.xml
new file mode 100644
index 0000000..4b31099
--- /dev/null
+++ b/.idea/customTargets.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..a0da399
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..24830a2
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..9661ac7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Autoarr/Autoarr.c b/Autoarr/Autoarr.c
deleted file mode 100644
index 074f210..0000000
--- a/Autoarr/Autoarr.c
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "Autoarr.h"
-
-define_Autoarr(uint8)
-define_Autoarr(int8)
-define_Autoarr(uint16)
-define_Autoarr(int16)
-define_Autoarr(uint32)
-define_Autoarr(int32)
-define_Autoarr(uint64)
-define_Autoarr(int64)
-define_Autoarr(float)
-define_Autoarr(double)
-define_Autoarr(Unitype)
-
-// right func to clear array of unitype values
-void Autoarr_free_Unitype(Autoarr(Unitype)* ar){
- Autoarr_foreach(ar, u,Unitype_free(u));
- Autoarr_free(ar);
-}
diff --git a/Hashtable/hash.c b/Hashtable/hash.c
deleted file mode 100644
index dfa6cb7..0000000
--- a/Hashtable/hash.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "hash.h"
-
-uint32 hash32(char *str){
- uint32 hash=5381;
- for (char c=*str;c;c=*(++str))
- hash=((hash<<5)+hash)+c;
- return hash;
-}
-
-uint64 hash64(char* str){
- uint64 hash = 0;
- for (char c=*str;c;c=*(++str))
- hash=c+(hash<<6)+(hash<<16)-hash;
- return hash;
-}
diff --git a/Hashtable/hash.h b/Hashtable/hash.h
deleted file mode 100644
index b3b7d2b..0000000
--- a/Hashtable/hash.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma once
-
-#if __cplusplus
-extern "C" {
-#endif
-
-#include "../base/base.h"
-
-// djb2 hash function from http:// www.cse.yorku.ca/~oz/hash.html
-uint32 hash32(char *str);
-// sdbm hash function
-uint64 hash64(char* str);
-
-#if __cplusplus
-}
-#endif
\ No newline at end of file
diff --git a/Makefile b/Makefile
index f6c333c..8d13a1d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,58 +1,18 @@
-SRC=$(wildcard [^tests]**/*.c)
-TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c)
+###### Building tasks #######
+build_test:
+ @build_scripts/build_test.sh
-OUTDIR=bin
-CMP=gcc
-OPT_ARGS=-O2 -flto
-WARN_ARGS=-Wall -Wno-discarded-qualifiers -std=c17
+build_test_dbg:
+ @build_scripts/build_test_dbg.sh
-all: clear_c clear_bin build_test build_lib
+build_lib:
+ @build_scripts/build_lib.sh
-clear_c:
- clear
+###### Testing tasks #######
+test: build_test
+ @build_scripts/test.sh
-clear_bin:
- @echo -e '\n\e[96m-------------[clear_bin]--------------\e[0m'
- rm -rf $(OUTDIR)
- mkdir $(OUTDIR)
+test_valgrind: build_test_dbg
+ @build_scripts/test_valgrind.sh
-clang: CMP=clang
-clang: WARN_ARGS=-Wall -Wno-ignored-qualifiers -Wno-incompatible-pointer-types-discards-qualifiers -std=c17
-clang: all
-
-######################################
-###### Build tasks #######
-######################################
-TEST_FILE=kerep_test.com
-TEST_ARGS=$(WARN_ARGS) $(SRC) $(TESTS) -o $(OUTDIR)/$(TEST_FILE)
-
-build_test:
- @echo -e '\n\e[96m-------------[build_test]-------------\e[0m'
- $(CMP) $(OPT_ARGS) $(TEST_ARGS)
-
-build_test_dbg:
- @echo -e '\n\e[96m-----------[build_test_dbg]-----------\e[0m'
- $(CMP) -g -O0 $(TEST_ARGS).dbg
-
-LIB_ARGS=$(OPT_ARGS) $(WARN_ARGS)\
- -fpic -shared -Wl,-soname,$(LIB_FILE)\
- $(SRC) tests/test_marshalling.c
-LIB_FILE=kerep.so
-
-build_lib:
- @echo -e '\n\e[96m-------------[build_lib]--------------\e[0m'
- $(CMP) $(LIB_ARGS) -o $(OUTDIR)/$(LIB_FILE)
-
-######################################
-###### Run tasks #######
-######################################
-test: clear_c build_test
- @echo -e '\n\e[96m-------------[build_test]-------------\e[0m'
- tabs 4
- $(OUTDIR)/$(TEST_FILE)
-
-valgrind: clear_c build_test_dbg
- @echo -e '\n\e[96m--------------[valgrind]--------------\e[0m'
- tabs 4
- valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \
- --leak-check=full --show-leak-kinds=all $(OUTDIR)/$(TEST_FILE).dbg
+all: build_test
diff --git a/build_scripts/build_lib.sh b/build_scripts/build_lib.sh
new file mode 100644
index 0000000..e0c7f55
--- /dev/null
+++ b/build_scripts/build_lib.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+source build_scripts/init.sh
+
+print "${CYAN}=============[build_lib]==============\n"
+clear_dir "$OUTDIR"
+clear_dir "$OBJDIR"
+compile_c "$BUILD_LIB_C_ARGS" "$SRC_C tests/test_marshalling.c"
+compile_cpp "$BUILD_LIB_CPP_ARGS" "$SRC_CPP"
+link "$BUILD_LIB_CPP_ARGS $BUILD_LIB_LINKER_ARGS" "$LIB_FILE"
diff --git a/build_scripts/build_test.sh b/build_scripts/build_test.sh
new file mode 100644
index 0000000..570de5a
--- /dev/null
+++ b/build_scripts/build_test.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+source build_scripts/init.sh
+
+print "${CYAN}=============[build_test]=============\n"
+clear_dir "$OUTDIR"
+clear_dir "$OBJDIR"
+compile_c "$BUILD_TEST_C_ARGS" "$SRC_C $TESTS_C"
+compile_cpp "$BUILD_TEST_CPP_ARGS" "$SRC_CPP $TESTS_CPP"
+link "$BUILD_TEST_CPP_ARGS $BUILD_TEST_LINKER_ARGS" $TEST_FILE
diff --git a/build_scripts/build_test_dbg.sh b/build_scripts/build_test_dbg.sh
new file mode 100644
index 0000000..ff56aa0
--- /dev/null
+++ b/build_scripts/build_test_dbg.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+source build_scripts/init.sh
+
+print "${CYAN}===========[build_test_dbg]===========\n"
+clear_dir "$OUTDIR"
+clear_dir "$OBJDIR"
+compile_c "$BUILD_TEST_DBG_C_ARGS" "$SRC_C $TESTS_C"
+compile_cpp "$BUILD_TEST_DBG_CPP_ARGS" "$SRC_CPP $TESTS_CPP"
+link "$BUILD_TEST_DBG_CPP_ARGS $BUILD_TEST_DBG_LINKER_ARGS" $TEST_DBG_FILE
diff --git a/build_scripts/colors.sh b/build_scripts/colors.sh
new file mode 100644
index 0000000..e3e8363
--- /dev/null
+++ b/build_scripts/colors.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+BLACK='\033[0;30m'
+GRAY='\033[0;37m'
+WHITE='\033[0;97m'
+RED='\033[0;91m'
+GREEN='\033[0;92m'
+YELLOW='\033[0;93m'
+BLUE='\033[0;94m'
+PURPLE='\033[0;95m'
+CYAN='\033[0;96m'
diff --git a/build_scripts/default.config.sh b/build_scripts/default.config.sh
new file mode 100644
index 0000000..fdc6b2e
--- /dev/null
+++ b/build_scripts/default.config.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+OUTDIR=bin
+OBJDIR=obj
+CMP_C=gcc
+CMP_CPP=g++
+STD_C=c11
+STD_CPP=c++17
+WARN_C="-Wall -Wno-discarded-qualifiers" #-Wextra
+WARN_CPP="-Wall -Wno-unused-variable -Wno-return-type" #-Wextra
+SRC_C="$( find src -name '*.c')"
+SRC_CPP="$( find src -name '*.cpp')"
+TESTS_C="$( find tests -name '*.c')"
+TESTS_CPP="$(find tests -name '*.cpp')"
+VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ --leak-check=full --show-leak-kinds=all"
+
+# build_lib
+LIB_FILE=kerep.so
+BUILD_LIB_C_ARGS="-O2 -fpic -flto -shared"
+BUILD_LIB_CPP_ARGS="$BUILD_LIB_C_ARGS"
+BUILD_LIB_LINKER_ARGS="-Wl,-soname,$LIB_FILE"
+
+# build_test
+TEST_FILE=kerep.com
+BUILD_TEST_C_ARGS="-O2"
+BUILD_TEST_CPP_ARGS="$BUILD_TEST_C_ARGS"
+BUILD_TEST_LINKER_ARGS=""
+
+# build_test_dbg
+TEST_DBG_FILE=$TEST_FILE
+BUILD_TEST_DBG_C_ARGS="-O0 -g"
+BUILD_TEST_DBG_CPP_ARGS="$BUILD_TEST_DBG_C_ARGS"
+BUILD_TEST_DBG_LINKER_ARGS=""
diff --git a/build_scripts/functions.sh b/build_scripts/functions.sh
new file mode 100644
index 0000000..0e09cc3
--- /dev/null
+++ b/build_scripts/functions.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+function print {
+ printf "$1$GRAY"
+}
+
+function clear_dir {
+ print "${BLUE}clearing $1\n"
+ rm -rf $1
+ mkdir $1
+}
+
+function compile {
+ local cmp=$1
+ print "${BLUE}compiler: ${GRAY}$cmp\n"
+ local std=$2
+ print "${BLUE}standard: ${GRAY}$std\n"
+ local warn=$3
+ print "${BLUE}warnings: ${GRAY}$warn\n"
+ local args=$4
+ print "${BLUE}args: ${GRAY}$args\n"
+ local sources=$5
+ print "${BLUE}sources: ${GRAY}$sources\n"
+ local compilation_error=0
+
+ for srcfile in $sources
+ do (
+ local object="$OBJDIR/$(basename $srcfile).o"
+ if ! $($cmp -std=$std $warn $args -c -o $object $srcfile)
+ then
+ print "${RED}some error happened\n"
+ compilation_error=1
+ fi
+ ) & done
+ wait
+
+ if [ $compilation_error != 0 ]
+ then
+ exit 1
+ fi
+}
+
+# (args, sources)
+function compile_c {
+ print "${CYAN}-------------[compile_c]--------------\n"
+ compile $CMP_C $STD_C "$WARN_C" "$1" "$2"
+}
+
+# (args, sources)
+function compile_cpp {
+ print "${CYAN}------------[compile_cpp]-------------\n"
+ compile $CMP_CPP $STD_CPP "$WARN_CPP" "$1" "$2"
+}
+
+# (args, outfile)
+function link {
+ print "${CYAN}----------------[link]----------------\n"
+ local args=$1
+ print "${BLUE}args: ${GRAY}$args\n"
+ local outfile=$OUTDIR/$2
+ print "${BLUE}outfile: ${GRAY}$outfile\n"
+ local objects="$(find $OBJDIR -name *.o)"
+ print "${BLUE}objects: ${GRAY}$objects\n"
+ if $CMP_CPP $args -o $outfile $(echo $objects | tr '\n' ' ')
+ then
+ print "${GREEN}file $CYAN$outfile ${GREEN}created\n"
+ rm -rf $OBJDIR
+ else
+ print "${RED}some error happened\n"
+ exit 1
+ fi
+}
diff --git a/build_scripts/init.sh b/build_scripts/init.sh
new file mode 100644
index 0000000..c249b95
--- /dev/null
+++ b/build_scripts/init.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+reset
+tabs 4
+
+source build_scripts/colors.sh
+source build_scripts/functions.sh
+
+if [ ! -f ".config" ]; then
+ print "${YELLOW}./.config doesn't exists\n"
+ cp build_scripts/default.config.sh .config
+ print "${YELLOW}default config created\n"
+ while true; do
+ print "${WHITE}continue? (y/n) "
+ read answ
+ case $answ in
+ [Yy] ) break;;
+ [Nn] ) exit;;
+ * ) print "${RED}incorrect answer\n";;
+ esac
+ done
+fi
+source .config
diff --git a/build_scripts/test.sh b/build_scripts/test.sh
new file mode 100644
index 0000000..45ac85c
--- /dev/null
+++ b/build_scripts/test.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+source build_scripts/init.sh
+
+print "${CYAN}================[test]================\n"
+cd $OUTDIR
+./$TEST_FILE
+cd ..
diff --git a/build_scripts/test_valgrind.sh b/build_scripts/test_valgrind.sh
new file mode 100644
index 0000000..a92df20
--- /dev/null
+++ b/build_scripts/test_valgrind.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+source build_scripts/init.sh
+
+print "${CYAN}===========[test_valgrind]============\n"
+cd $OUTDIR
+valgrind $VALGRIND_ARGS ./$TEST_DBG_FILE
+cat "valgrind.log"
+cd ..
diff --git a/kerep.vcxproj b/kerep.vcxproj
index 9159891..cd2ba68 100644
--- a/kerep.vcxproj
+++ b/kerep.vcxproj
@@ -18,6 +18,58 @@
x64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
16.0
Win32Proj
@@ -112,7 +164,7 @@
/Zc:twoPhase- /MP %(AdditionalOptions)
Default
- Default
+ stdcpp20
None
Disabled
@@ -139,7 +191,7 @@
/Zc:twoPhase- /MP %(AdditionalOptions)
MultiThreadedDLL
Default
- Default
+ stdcpp20
None
@@ -164,7 +216,7 @@
/Zc:twoPhase- /MP %(AdditionalOptions)
Default
- Default
+ stdcpp20
None
@@ -184,13 +236,13 @@
NotUsing
- stdc11
+ stdc17
Speed
/Zc:twoPhase- /MP %(AdditionalOptions)
MultiThreadedDLL
Default
- Default
+ stdcpp20
None
@@ -201,51 +253,6 @@
false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/kerep.vcxproj.filters b/kerep.vcxproj.filters
deleted file mode 100644
index e6b847a..0000000
--- a/kerep.vcxproj.filters
+++ /dev/null
@@ -1,144 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
- Файлы заголовков
-
-
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
- Исходные файлы
-
-
-
\ No newline at end of file
diff --git a/src/Autoarr/Autoarr.c b/src/Autoarr/Autoarr.c
new file mode 100644
index 0000000..90346bb
--- /dev/null
+++ b/src/Autoarr/Autoarr.c
@@ -0,0 +1,19 @@
+#include "Autoarr.h"
+
+Autoarr_define(uint8)
+Autoarr_define(int8)
+Autoarr_define(uint16)
+Autoarr_define(int16)
+Autoarr_define(uint32);
+Autoarr_define(int32);
+Autoarr_define(uint64);
+Autoarr_define(int64);
+Autoarr_define(float);
+Autoarr_define(double);
+Autoarr_define(Unitype);
+
+// right func to clear array of unitype values
+void Autoarr_free_Unitype(Autoarr(Unitype)* ar){
+ Autoarr_foreach(ar, u,Unitype_free(u));
+ Autoarr_free(ar);
+}
diff --git a/Autoarr/Autoarr.h b/src/Autoarr/Autoarr.h
similarity index 74%
rename from Autoarr/Autoarr.h
rename to src/Autoarr/Autoarr.h
index 9e7d996..89440a4 100644
--- a/Autoarr/Autoarr.h
+++ b/src/Autoarr/Autoarr.h
@@ -7,17 +7,17 @@ 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)
+Autoarr_declare(uint8)
+Autoarr_declare(int8)
+Autoarr_declare(uint16)
+Autoarr_declare(int16)
+Autoarr_declare(uint32)
+Autoarr_declare(int32)
+Autoarr_declare(uint64)
+Autoarr_declare(int64)
+Autoarr_declare(float)
+Autoarr_declare(double)
+Autoarr_declare(Unitype)
// right func to clear array of unitype values
void Autoarr_free_Unitype(Autoarr(Unitype)* ar);
diff --git a/Autoarr/Autoarr_KVPair_exported.c b/src/Autoarr/Autoarr_KVPair_exported.c
similarity index 100%
rename from Autoarr/Autoarr_KVPair_exported.c
rename to src/Autoarr/Autoarr_KVPair_exported.c
diff --git a/Autoarr/Autoarr_Unitype_exported.c b/src/Autoarr/Autoarr_Unitype_exported.c
similarity index 100%
rename from Autoarr/Autoarr_Unitype_exported.c
rename to src/Autoarr/Autoarr_Unitype_exported.c
diff --git a/Autoarr/Autoarr_declare.h b/src/Autoarr/Autoarr_declare.h
similarity index 98%
rename from Autoarr/Autoarr_declare.h
rename to src/Autoarr/Autoarr_declare.h
index 5ed5240..80169bd 100644
--- a/Autoarr/Autoarr_declare.h
+++ b/src/Autoarr/Autoarr_declare.h
@@ -6,7 +6,7 @@ extern "C" {
#include "../base/base.h"
-#define declare_Autoarr(type)\
+#define Autoarr_declare(type)\
\
struct Autoarr_##type;\
\
diff --git a/Autoarr/Autoarr_define.h b/src/Autoarr/Autoarr_define.h
similarity index 98%
rename from Autoarr/Autoarr_define.h
rename to src/Autoarr/Autoarr_define.h
index 6e81b81..441c9b6 100644
--- a/Autoarr/Autoarr_define.h
+++ b/src/Autoarr/Autoarr_define.h
@@ -6,7 +6,7 @@ extern "C" {
#include "../base/base.h"
-#define define_Autoarr(type)\
+#define Autoarr_define(type)\
\
void __Autoarr_add_##type(Autoarr_##type* ar, type element){\
if(!ar->values){\
diff --git a/src/Autoarr2/Autoarr2.hpp b/src/Autoarr2/Autoarr2.hpp
new file mode 100644
index 0000000..c3f4790
--- /dev/null
+++ b/src/Autoarr2/Autoarr2.hpp
@@ -0,0 +1,122 @@
+#pragma once
+
+#include "../base/base.h"
+
+#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
+#define Autoarr2_NO_REZULT (uint32)-1
+
+
+template
+class Autoarr2 {
+ T** values;
+public:
+ uint16 blocks_count;
+ uint16 block_length;
+ uint16 max_block_length;
+ uint32 length;
+
+ Autoarr2();
+ explicit Autoarr2(uint16 _max_block_length);
+ virtual ~Autoarr2();
+
+ T* getptr(uint32 index);
+ T get(uint32 index);
+ void set(uint32 index, T value);
+ void add(T value);
+ void remove(uint32 index);
+
+ // returns index of the first inclusion
+ // using to compare values
+ template
+ uint32 search(T& value, cmp_func_lambda cmpf, uint32 fromIndex, uint32 toIndex);
+ template
+ uint32 search(T& value, cmp_func_lambda cmpf, uint32 fromIndex);
+ template
+ uint32 search(T& value, cmp_func_lambda cmpf);
+};
+
+template
+Autoarr2::Autoarr2(uint16 _max_block_length) {
+ values = NULL;
+ block_length = 0;
+ blocks_count = 0;
+ length = 0;
+ max_block_length=_max_block_length;
+}
+
+template
+Autoarr2::Autoarr2() : Autoarr2(__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT) {}
+
+template
+Autoarr2::~Autoarr2() {
+ for (uint16 i=0;i
+T *Autoarr2::getptr(uint32 index) {
+ if(index>=length) throw_id(ERR_WRONGINDEX);
+ return values[index/max_block_length]+index%max_block_length;
+}
+
+template
+T Autoarr2::get(uint32 index) {
+ return *getptr(index);
+}
+
+template
+void Autoarr2::set(uint32 index, T value) {
+ *getptr(index)=value;
+}
+
+template
+void Autoarr2::add(T value) {
+ if(!values){
+ values=new T*[1];
+ goto create_block;
+ }
+ else if(block_length==max_block_length){
+ block_length=0;
+create_block:
+ T** new_values=new T*[blocks_count+1];
+ for(uint32 i=0;i
+template
+uint32 Autoarr2::search(T& value, cmp_func_lambda cmpf, uint32 fromIndex, uint32 toIndex){
+ uint32 index=fromIndex;
+ for(; index
+template
+uint32 Autoarr2::search(T& value, cmp_func_lambda cmpf, uint32 fromIndex){
+ return search(value, cmpf, fromIndex, length);
+}
+
+template
+template
+uint32 Autoarr2::search(T& value, cmp_func_lambda cmpf){
+ return search(value, cmpf, 0, length);
+}
+
+template
+void Autoarr2::remove(uint32 index){
+ throw_id(ERR_NOTIMPLEMENTED);
+}
\ No newline at end of file
diff --git a/DtsodParser/DtsodV24.c b/src/DtsodParser/DtsodV24.c
similarity index 100%
rename from DtsodParser/DtsodV24.c
rename to src/DtsodParser/DtsodV24.c
diff --git a/DtsodParser/DtsodV24.h b/src/DtsodParser/DtsodV24.h
similarity index 100%
rename from DtsodParser/DtsodV24.h
rename to src/DtsodParser/DtsodV24.h
diff --git a/DtsodParser/DtsodV24_deserialize.c b/src/DtsodParser/DtsodV24_deserialize.c
similarity index 98%
rename from DtsodParser/DtsodV24_deserialize.c
rename to src/DtsodParser/DtsodV24_deserialize.c
index 1c1a09c..f8dd4d0 100644
--- a/DtsodParser/DtsodV24_deserialize.c
+++ b/src/DtsodParser/DtsodV24_deserialize.c
@@ -44,7 +44,7 @@ Maybe ERROR_WRONGCHAR(const char c, char* _text, char* text_first, const char* s
if(!_c) break;
}
char errmsg[1024];
- IFWIN(
+ IFMSC(
sprintf_s(errmsg,1024, "unexpected <%c> at:\n"
" \"%s\"\n"
"\\___[%s:%d] %s()",
@@ -85,7 +85,6 @@ Maybe __ReadName(DeserializeSharedData* shared){
case '[': case ']':
case '{':
safethrow_wrongchar(c,;);
- break;
case '#': ;
char _c=c;
char* _text=text;
@@ -180,7 +179,6 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
else if(string_compare(str,falseStr))
return SUCCESS(UniFalse);
else safethrow_wrongchar(*str.ptr,;);
- break;
// Float64
case 'f': {
char* _c=string_extract(str);
@@ -192,9 +190,9 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
case 'u': {
uint64 lu=0;
char* _c=string_extract(str);
- if(sscanf(_c,"%lu",&lu)!=1){
+ if(sscanf(_c, IFWIN("%llu", "%lu"), &lu)!=1){
char err[64];
- IFWIN(
+ IFMSC(
sprintf_s(err,64,"can't parse to int: <%s>",_c),
sprintf(err,"can't parse to int: <%s>",_c)
);
@@ -208,9 +206,9 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
case '5': case '6': case '7': case '8': case '9': {
int64 li=0;
char* _c=string_extract(str);
- if(sscanf(_c,"%li",&li)!=1){
+ if(sscanf(_c, IFWIN("%lli", "%li"), &li)!=1){
char err[64];
- IFWIN(
+ IFMSC(
sprintf_s(err,64,"can't parse to int: <%s>",_c),
sprintf(err,"can't parse to int: <%s>",_c)
);
@@ -245,7 +243,6 @@ Maybe __ReadValue(DeserializeSharedData* shared, bool* readingList){
case '}': case '$':
case '\'':
safethrow_wrongchar(c,Unitype_free(value));
- break;
case '#':;
char _c=c;
char* _text=text;
diff --git a/DtsodParser/DtsodV24_exported.c b/src/DtsodParser/DtsodV24_exported.c
similarity index 100%
rename from DtsodParser/DtsodV24_exported.c
rename to src/DtsodParser/DtsodV24_exported.c
diff --git a/DtsodParser/DtsodV24_serialize.c b/src/DtsodParser/DtsodV24_serialize.c
similarity index 96%
rename from DtsodParser/DtsodV24_serialize.c
rename to src/DtsodParser/DtsodV24_serialize.c
index 4a6181e..4618104 100644
--- a/DtsodParser/DtsodV24_serialize.c
+++ b/src/DtsodParser/DtsodV24_serialize.c
@@ -49,7 +49,6 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
break;
case Null:
safethrow("Null isn't supported in DtsodV24",;);
- break;
case AutoarrUnitypePtr:
if(Autoarr_length(((Autoarr_Unitype*)(u.VoidPtr)))){
addc('\n');
@@ -79,7 +78,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
goto hashtableNotBlank;
if(__.key); // weird way to disable warning
}));
-
+
// blank hashtable
addc('{');
@@ -96,7 +95,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
AppendTabs();
addc('}');
break;
- default: dbg((u.type)); safethrow(ERR_WRONGTYPE,;);
+ default: dbg((u.type)); safethrow(ERR_WRONGTYPE,;);
}
return MaybeNull;
@@ -104,11 +103,11 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
Maybe __serialize(StringBuilder* _b, uint8 _tabs, Hashtable* dtsod){
SerializeSharedData _shared={
- .sh_builder=_b,
+ .sh_builder=_b,
.sh_tabs=_tabs
};
SerializeSharedData* shared=&_shared;
-
+
Hashtable_foreach(dtsod, p, ({
AppendTabs();
StringBuilder_append_cptr(b,p.key);
diff --git a/DtsodParser/README.md b/src/DtsodParser/README.md
similarity index 100%
rename from DtsodParser/README.md
rename to src/DtsodParser/README.md
diff --git a/src/HashFunctions/hash.c b/src/HashFunctions/hash.c
new file mode 100644
index 0000000..9035ef0
--- /dev/null
+++ b/src/HashFunctions/hash.c
@@ -0,0 +1,111 @@
+#include "hash.h"
+
+uint32 hash_sdbm32(uint32 oldhash, void* buf, uint32 len){
+ uint8* ubuf=(uint8*)buf;
+ register uint32 hash=oldhash;
+ for (; len ; len--, ubuf++)
+ hash=(hash<<6)+(hash<<16)-hash+*ubuf;
+ return hash;
+}
+
+static const uint32 crc_32_tab[]={
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
+ 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
+ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
+ 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
+ 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
+ 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
+ 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
+ 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
+ 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
+ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
+ 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
+ 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
+ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
+ 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
+ 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
+ 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
+ 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
+ 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
+ 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
+ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
+ 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
+ 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+};
+
+uint32 hash_crc32(uint32 oldhash, void* buf, uint32 len){
+ uint8* ubuf=(uint8*)buf;
+ register uint32 crc=oldhash;
+ for (; len; --len, ++ubuf)
+ crc=crc_32_tab[(crc^(*ubuf)) & 0xff] ^ (crc>>8);
+ return ~crc;
+}
+
+
+// bool hashf_crc32c(char *name, uint32 *crc, long *charcnt) {
+// register FILE *fin;
+// register uint32 oldcrc32;
+// register int c;
+
+// oldcrc32 = 0xFFFFFFFF; *charcnt = 0;
+// if ((fin=fopen(name, "r"))==NULL) {
+// perror(name);
+// return false;
+// }
+// while ((c=getc(fin))!=EOF) {
+// ++*charcnt;
+// oldcrc32 = UPDC32(c, oldcrc32);
+// }
+
+// if (ferror(fin)) {
+// perror(name);
+// *charcnt = -1;
+// }
+
+// fclose(fin);
+
+// *crc = oldcrc32 = ~oldcrc32;
+// return true;
+// }
diff --git a/src/HashFunctions/hash.h b/src/HashFunctions/hash.h
new file mode 100644
index 0000000..753ed11
--- /dev/null
+++ b/src/HashFunctions/hash.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#if __cplusplus
+extern "C" {
+#endif
+
+#include "../base/base.h"
+
+#define hashb(FUNC, BUF, LEN) FUNC(0xFFFFFFFF, BUF, LEN)
+#define hashs(FUNC, STR) FUNC(0xFFFFFFFF, STR, cptr_length(STR))
+
+uint32 hash_sdbm32(uint32 oldhash, void* buf, uint32 len);
+uint32 hash_crc32(uint32 oldhash, void* buf, uint32 len);
+
+#if __cplusplus
+}
+#endif
\ No newline at end of file
diff --git a/Hashtable/Hashtable.c b/src/Hashtable/Hashtable.c
similarity index 89%
rename from Hashtable/Hashtable.c
rename to src/Hashtable/Hashtable.c
index d8c680b..992ef5e 100644
--- a/Hashtable/Hashtable.c
+++ b/src/Hashtable/Hashtable.c
@@ -37,14 +37,12 @@ void Hashtable_expand(Hashtable* ht){
for(uint16 i=0;ihein-1];i++){
Autoarr(KVPair)* ar=ht->rows[i];
uint32 arlen=Autoarr_length(ar);
- for(uint16 k=0;khein];
+ uint16 newrown=hashs(hash_sdbm32, p.key)%HT_HEIGHTS[ht->hein];
Autoarr(KVPair)* newar=newrows[newrown];
Autoarr_add(newar,p);
}
- // it is a feature, not a bug
- // no need to free kvpair keys and values, they just moved to new autoarrs
Autoarr_free(ar);
}
@@ -53,10 +51,10 @@ void Hashtable_expand(Hashtable* ht){
}
Autoarr(KVPair)* getrow(Hashtable* ht, char* key, bool can_expand){
- uint32 hash=hash32(key);
+ uint32 hash=hashs(hash_sdbm32, key);
Autoarr(KVPair)* ar=ht->rows[hash%HT_HEIGHTS[ht->hein]];
if(can_expand && Autoarr_length(ar)==Autoarr_max_length(ar))
- optime("expand",1,(Hashtable_expand(ht)));
+ Hashtable_expand(ht);
ar=ht->rows[hash%HT_HEIGHTS[ht->hein]];
return ar;
}
diff --git a/Hashtable/Hashtable.h b/src/Hashtable/Hashtable.h
similarity index 95%
rename from Hashtable/Hashtable.h
rename to src/Hashtable/Hashtable.h
index 19eca90..3500199 100644
--- a/Hashtable/Hashtable.h
+++ b/src/Hashtable/Hashtable.h
@@ -4,8 +4,7 @@
extern "C" {
#endif
-#include "../base/base.h"
-#include "hash.h"
+#include "../HashFunctions/hash.h"
#include "KeyValuePair.h"
typedef struct Hashtable{
diff --git a/Hashtable/KeyValuePair.c b/src/Hashtable/KeyValuePair.c
similarity index 94%
rename from Hashtable/KeyValuePair.c
rename to src/Hashtable/KeyValuePair.c
index 8ba43ae..cbe22dd 100644
--- a/Hashtable/KeyValuePair.c
+++ b/src/Hashtable/KeyValuePair.c
@@ -1,6 +1,6 @@
#include "KeyValuePair.h"
-define_Autoarr(KVPair)
+Autoarr_define(KVPair)
// proper way to clear a KVP
diff --git a/Hashtable/KeyValuePair.h b/src/Hashtable/KeyValuePair.h
similarity index 93%
rename from Hashtable/KeyValuePair.h
rename to src/Hashtable/KeyValuePair.h
index ac7a666..19cc277 100644
--- a/Hashtable/KeyValuePair.h
+++ b/src/Hashtable/KeyValuePair.h
@@ -12,7 +12,7 @@ typedef struct KVPair{
Unitype value;
} KVPair;
-declare_Autoarr(KVPair)
+Autoarr_declare(KVPair)
// proper way to clear a KVP
void KVPair_free(KVPair p);
diff --git a/src/Hashtable2/Hashtable2.hpp b/src/Hashtable2/Hashtable2.hpp
new file mode 100644
index 0000000..63fd667
--- /dev/null
+++ b/src/Hashtable2/Hashtable2.hpp
@@ -0,0 +1,209 @@
+#pragma once
+
+#include "../HashFunctions/hash.h"
+#include "../Autoarr2/Autoarr2.hpp"
+#include
+
+// amount of rows
+typedef uint32 HT_HEIGHT_T;
+typedef uint32 HT_HASH_T;
+
+#define STORE_HASHES 0
+
+static const HT_HEIGHT_T HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521};
+#define _HT_HEIN_MIN 0
+#define _HT_HEIN_MAX 6
+
+#define _HT_ARR_BC 2
+#define _HT_ARR_BL 8
+
+
+template
+class Hashtable2{
+// internal types
+ struct KeyValue{
+ TKey key;
+ TVal value;
+#if STORE_HASHES
+ HT_HASH_T hash;
+#endif
+ };
+ //using HashKeyFunc_t=HT_HASH_T (*)(TKey);
+ using HashKeyFunc_t=std::function;
+ using KeyCmpFunc_t=std::function;
+
+// fields
+ Autoarr2** rows;
+
+ HashKeyFunc_t hashKeyFunc;
+#if !STORE_HASHES
+ KeyCmpFunc_t keyComparFunc;
+#endif
+public:
+ HT_HEIGHT_T height;
+private:
+ uint8 hein;
+
+// constructors
+#if STORE_HASHES
+public:
+#endif
+ Hashtable2(HashKeyFunc_t _hashKeyFunc);
+#if !STORE_HASHES
+public:
+ explicit Hashtable2(HashKeyFunc_t _hashKeyFunc, KeyCmpFunc_t _keyComparFunc);
+#endif
+
+
+// methods
+private:
+ void free_rows();
+ TVal* getptr(TKey key, HT_HASH_T& keyHash, HT_HEIGHT_T& rowN);
+ void expand();
+ void add(TKey& key, TVal& value, HT_HASH_T keyHash, HT_HEIGHT_T rowN);
+
+public:
+ virtual ~Hashtable2();
+ TVal* getptr(TKey key);
+ TVal get(TKey key);
+ bool tryGet(TKey key, TVal* output);
+ void add(TKey key, TVal value);
+ void addOrSet(TKey key, TVal value);
+ void remove(TKey key);
+};
+
+
+template
+Hashtable2::Hashtable2(HashKeyFunc_t _hashKeyFunc){
+ hashKeyFunc=_hashKeyFunc;
+ hein=_HT_HEIN_MIN;
+ height=HT_HEIGHTS[hein];
+ rows=new Autoarr2*[height];
+ for(HT_HEIGHT_T i=0; i(_HT_ARR_BL);
+}
+
+#if !STORE_HASHES
+template
+Hashtable2::Hashtable2(HashKeyFunc_t _hashKeyFunc, KeyCmpFunc_t _keyComparFunc) : Hashtable2(_hashKeyFunc) {
+ keyComparFunc=_keyComparFunc;
+}
+#endif
+
+
+
+template
+void Hashtable2::free_rows(){
+ for(uint32 i=0; i< height; i++)
+ delete rows[i];
+ delete[] rows;
+}
+
+template
+Hashtable2::~Hashtable2() { free_rows(); }
+
+
+template
+TVal* Hashtable2::getptr(TKey key, HT_HASH_T& keyHash, HT_HEIGHT_T& rowN){
+ keyHash=hashKeyFunc(key);
+ rowN=keyHash%height;
+ KeyValue kv;
+#if STORE_HASHES
+ kv.hash=keyHash;
+ uint32 index=rows[rowN]->search(kv, [](KeyValue kv0, KeyValue kv1) { return kv0.hash==kv1.hash; });
+#else
+ kv.key=key;
+ uint32 index=rows[rowN]->search(kv, [this](KeyValue kv0, KeyValue kv1) { return this->keyComparFunc(kv0.key, kv1.key); });
+#endif
+ if(index==Autoarr2_NO_REZULT)
+ return NULL;
+ return &(rows[rowN]->getptr(index))->value;
+}
+
+template
+TVal* Hashtable2::getptr(TKey key){
+ HT_HASH_T keyHash;
+ HT_HEIGHT_T rowN;
+ return getptr(key, keyHash, rowN);
+}
+
+template
+TVal Hashtable2::get(TKey key){
+ TVal* ptr=getptr(key);
+ if(!ptr)
+ throw_id(ERR_KEYNOTFOUND);
+ return *ptr;
+}
+
+template
+bool Hashtable2::tryGet(TKey key, TVal* output){
+ TVal* ptr=getptr(key);
+ if(!ptr)
+ return false;
+ *output=*ptr;
+ return true;
+}
+
+template
+void Hashtable2::expand(){
+ printf("expand\n"); fflush(stdout);
+ if(hein>=_HT_HEIN_MAX)
+ throw_id(ERR_MAXLENGTH);
+
+ uint32 newHeight=HT_HEIGHTS[++hein];
+ Autoarr2** newRows=new Autoarr2*[newHeight];
+ for(HT_HEIGHT_T i=0; i(_HT_ARR_BL);
+
+ for(HT_HEIGHT_T oldRowN=0; oldRowNlength; k++){
+ KeyValue kv=rows[oldRowN]->get(k);
+#if STORE_HASHES
+ HT_HEIGHT_T newRowN=kv.hash%newHeight;
+#else
+ HT_HEIGHT_T newRowN=hashKeyFunc(kv.key)%newHeight;
+#endif
+ newRows[newRowN]->add(kv);
+ }
+
+ free_rows();
+ height=newHeight;
+ rows=newRows;
+}
+
+template
+void Hashtable2::add(TKey& key, TVal& value, HT_HASH_T keyHash, HT_HEIGHT_T rowN){
+ printf("add\n"); fflush(stdout);
+ Autoarr2* row=rows[rowN];
+ if(row->length == _HT_ARR_BC*_HT_ARR_BL)
+ expand();
+ KeyValue kv;
+ kv.key=key;
+ kv.value=value;
+#if STORE_HASHES
+ kv.hash=keyHash;
+#endif
+ row->add(kv);
+}
+
+template
+void Hashtable2::add(TKey key, TVal value){
+ HT_HASH_T keyHash=hashKeyFunc(key);
+ HT_HEIGHT_T rowN=keyHash%height;
+ add(key, value, keyHash, rowN);
+}
+
+template
+void Hashtable2::addOrSet(TKey key, TVal value){
+ HT_HASH_T keyHash;
+ HT_HEIGHT_T rowN;
+ TVal* valptr=getptr(key, keyHash, rowN);
+ if(valptr) *valptr=value;
+ else add(key, value, keyHash, rowN);
+}
+
+
+template
+void Hashtable2::remove(TKey key){
+ throw_id(ERR_NOTIMPLEMENTED);
+}
diff --git a/src/Network/knSocket.c b/src/Network/knSocket.c
new file mode 100644
index 0000000..f0dec47
--- /dev/null
+++ b/src/Network/knSocket.c
@@ -0,0 +1 @@
+#include "network.h"
\ No newline at end of file
diff --git a/src/Network/network.h b/src/Network/network.h
new file mode 100644
index 0000000..f877cac
--- /dev/null
+++ b/src/Network/network.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#if __cplusplus
+extern "C" {
+#endif
+
+#include "../Hashtable/Hashtable.h"
+
+#if defined(_MSC_VER) || defined(_WIN64) || defined(_WIN32)
+ #include "winsock.h"
+#else
+ #include "../Hashtable/Hashtable.h"
+ #include
+ #include
+ #include
+ #include
+#endif
+
+#define KNPAC_MAX_DATA_SIZE 65503
+
+typedef struct knPackage{
+ char header[5]; // knpac
+ uint8 version; // protocol version
+ uint16 data_size; // size of data block in bytes (1-)
+ uint32 package_num; // number in sequence of sent packages
+ uint32 destination_hash; // hash32 of knDestination.name
+ uint64 data_hash; // hash64 of data
+ uint8* data; // ptr to data
+} knPackage;
+
+typedef struct knDestination{
+ char* name;
+
+} knDestination;
+
+typedef struct knSocket {
+ Hashtable* destinations;
+ int socketfd;
+} knSocket;
+
+#if __cplusplus
+}
+#endif
\ No newline at end of file
diff --git a/SearchTree/SearchTree.c b/src/SearchTree/SearchTree.c
similarity index 80%
rename from SearchTree/SearchTree.c
rename to src/SearchTree/SearchTree.c
index 8f86ab4..e7cfac6 100644
--- a/SearchTree/SearchTree.c
+++ b/src/SearchTree/SearchTree.c
@@ -45,11 +45,16 @@ indexes3 splitindex(uint8 i){
};
}
-void ST_push(STNode* node_first, const char* key, Unitype value){
+void ST_push(STNode* node_first, char* key, Unitype value){
+ string keyString={key, cptr_length(key)};
+ ST_pushString(node_first, keyString, value);
+}
+
+void ST_pushString(STNode* node_first, string key, Unitype value){
if (!node_first) throw(ERR_NULLPTR);
STNode* node_last=node_first;
- while(*key){
- indexes3 i3=splitindex((uint8)*key);
+ while(key.length--){
+ indexes3 i3=splitindex((uint8)*key.ptr);
if(!node_last->branches){
node_last->branches=(STNode****)malloc(8*sizeof(STNode***));
for(uint8 i=0;i<8;i++)
@@ -68,16 +73,21 @@ void ST_push(STNode* node_first, const char* key, Unitype value){
if(!node_last->branches[i3.n32][i3.n4][i3.rem])
node_last->branches[i3.n32][i3.n4][i3.rem]=STNode_create();
node_last=node_last->branches[i3.n32][i3.n4][i3.rem];
- key++;
+ key.ptr++;
}
node_last->value=value;
}
-Unitype ST_pull(STNode* node_first, const char* key){
+Unitype ST_pull(STNode* node_first, char* key){
+ string keyString={key, cptr_length(key)};
+ return ST_pullString(node_first, keyString);
+}
+
+Unitype ST_pullString(STNode* node_first, string key){
if (!node_first) throw(ERR_NULLPTR);
STNode* node_last=node_first;
- while (*key){
- indexes3 i3=splitindex((uint8)*key);
+ while (key.length--){
+ indexes3 i3=splitindex((uint8)*key.ptr);
if(!node_last->branches) return UniNull;
STNode*** ptrn32=(STNode***)node_last->branches[i3.n32];
if(!ptrn32) return UniNull;
@@ -85,7 +95,7 @@ Unitype ST_pull(STNode* node_first, const char* key){
if(!ptrn4) return UniNull;
node_last=ptrn4[i3.rem];
if(!node_last) return UniNull;
- key++;
+ key.ptr++;
}
return node_last->value;
}
diff --git a/SearchTree/SearchTree.h b/src/SearchTree/SearchTree.h
similarity index 54%
rename from SearchTree/SearchTree.h
rename to src/SearchTree/SearchTree.h
index 4d83bb1..fc4eb8c 100644
--- a/SearchTree/SearchTree.h
+++ b/src/SearchTree/SearchTree.h
@@ -5,6 +5,7 @@ extern "C" {
#endif
#include "../base/base.h"
+#include "../String/string.h"
typedef struct SearchTreeNode{
struct SearchTreeNode**** branches; // *STNode[8][8][4]
@@ -14,8 +15,10 @@ typedef struct SearchTreeNode{
STNode* STNode_create();
void STNode_free(STNode* node);
-void ST_push(STNode* node, const char* key, Unitype value);
-Unitype ST_pull(STNode* node, const char* key);
+void ST_push(STNode* node, char* key, Unitype value);
+void ST_pushString(STNode* node, string key, Unitype value);
+Unitype ST_pull(STNode* node, char* key);
+Unitype ST_pullString(STNode* node, string key);
#if __cplusplus
}
diff --git a/SearchTree/SearchTree.md b/src/SearchTree/SearchTree.md
similarity index 100%
rename from SearchTree/SearchTree.md
rename to src/SearchTree/SearchTree.md
diff --git a/String/StringBuilder.c b/src/String/StringBuilder.c
similarity index 98%
rename from String/StringBuilder.c
rename to src/String/StringBuilder.c
index f6d7f54..c0b46a9 100644
--- a/String/StringBuilder.c
+++ b/src/String/StringBuilder.c
@@ -1,8 +1,7 @@
#include "StringBuilder.h"
-define_Autoarr(string)
+Autoarr_define(string)
-#define MAXLENGTH 32768
#define BL_C 32
#define BL_L 1024
@@ -136,7 +135,7 @@ void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
void StringBuilder_append_float64(StringBuilder* b, double a){
try_complete_buf(b);
char buf[32];
- IFWIN(
+ IFMSC(
sprintf_s(buf,32,"%lf",a),
sprintf(buf,"%lf",a)
);
diff --git a/String/StringBuilder.h b/src/String/StringBuilder.h
similarity index 94%
rename from String/StringBuilder.h
rename to src/String/StringBuilder.h
index d1ed61f..8e19420 100644
--- a/String/StringBuilder.h
+++ b/src/String/StringBuilder.h
@@ -5,9 +5,9 @@ extern "C" {
#endif
#include "../Autoarr/Autoarr.h"
-#include "../String/string.h"
+#include "string.h"
-declare_Autoarr(string)
+Autoarr_declare(string)
typedef struct StringBuilder{
Autoarr(string)* compl_bufs;
diff --git a/String/string.c b/src/String/string.c
similarity index 97%
rename from String/string.c
rename to src/String/string.c
index 80699e4..2926359 100644
--- a/String/string.c
+++ b/src/String/string.c
@@ -1,4 +1,4 @@
-#include "../String/string.h"
+#include "string.h"
// copies str content to new char pointer value (adding '\0' at the end)
char* string_extract(string str){
diff --git a/String/string.h b/src/String/string.h
similarity index 100%
rename from String/string.h
rename to src/String/string.h
diff --git a/src/base/base.h b/src/base/base.h
new file mode 100644
index 0000000..d49b6d7
--- /dev/null
+++ b/src/base/base.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#if __cplusplus
+extern "C" {
+#endif
+
+#include "std.h"
+#include "types.h"
+#include "errors.h"
+#include "cptr.h"
+#include "optime.h"
+
+#if __cplusplus
+}
+#endif
\ No newline at end of file
diff --git a/base/cptr.c b/src/base/cptr.c
similarity index 87%
rename from base/cptr.c
rename to src/base/cptr.c
index 210dd84..22a6b36 100644
--- a/base/cptr.c
+++ b/src/base/cptr.c
@@ -9,9 +9,9 @@ uint32 cptr_length(char* str){
// allocates new char[] and copies src there
char* cptr_copy(char* src){
- uint32 len=cptr_length(src);
- char* dst=malloc(len+1);
- while(len-->0)
+ uint32 len=cptr_length(src)+1;
+ char* dst=malloc(len);
+ while(len--!=0)
dst[len]=src[len];
return dst;
}
@@ -30,7 +30,7 @@ bool cptr_compare(char* key0, char* key1){
char* char_multiply(char c, uint32 n){
char* rez=malloc(n+1);
rez[n]=0;
- while(n-->0)
+ while(n--!=0)
rez[n]=c;
return rez;
}
diff --git a/base/cptr.h b/src/base/cptr.h
similarity index 100%
rename from base/cptr.h
rename to src/base/cptr.h
diff --git a/base/errors.c b/src/base/errors.c
similarity index 90%
rename from base/errors.c
rename to src/base/errors.c
index f56687a..e3f61a2 100644
--- a/base/errors.c
+++ b/src/base/errors.c
@@ -2,7 +2,7 @@
#include "errors.h"
#include "cptr.h"
-char* errname(err_t err){
+char* errname(ErrorId err){
switch(err){
case SUCCESS: return "SUCCESS";
case ERR_MAXLENGTH: return "ERR_MAXLENGTH";
@@ -11,6 +11,7 @@ char* errname(err_t err){
case ERR_NOTIMPLEMENTED: return "ERR_NOTIMPLEMENTED";
case ERR_NULLPTR: return "ERR_NULLPTR";
case ERR_ENDOFSTR: return "ERR_ENDOFSTR";
+ case ERR_KEYNOTFOUND: return "ERR_KEYNOTFOUND";
default: return "UNKNOWN_ERROR";
}
}
@@ -20,7 +21,7 @@ char* errname(err_t err){
char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){
size_t bufsize=ERRMSG_MAXLENGTH;
char* rezult=malloc(bufsize);
- IFWIN(
+ IFMSC(
sprintf_s(rezult,bufsize,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg),
sprintf(rezult,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg)
);
@@ -30,7 +31,7 @@ char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char*
char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){
size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH;
char* rezult=malloc(bufsize);
- IFWIN(
+ IFMSC(
sprintf_s(rezult,bufsize,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname),
sprintf(rezult,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname)
);
@@ -42,10 +43,12 @@ void Maybe_free(Maybe e){
free(e.errmsg);
Unitype_free(e.value);
}
+
void printMaybe(Maybe e){
if(e.errmsg) printf("%s\n",e.errmsg);
else printuni(e.value);
}
char* __doNothing(char* a) {return a;}
-char* __unknownErr() {return "UNKNOWN ERROR";}
\ No newline at end of file
+
+char* __unknownErr() {return "UNKNOWN ERROR";}
diff --git a/base/errors.h b/src/base/errors.h
similarity index 64%
rename from base/errors.h
rename to src/base/errors.h
index 84e0b1a..de7c713 100644
--- a/base/errors.h
+++ b/src/base/errors.h
@@ -7,12 +7,14 @@ extern "C" {
#include "std.h"
#include "types.h"
-typedef enum err_t {
+typedef enum ErrorId {
SUCCESS, // not an error
- ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR
-} err_t;
+ ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX,
+ ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR,
+ ERR_KEYNOTFOUND
+} ErrorId;
-char* errname(err_t err);
+char* errname(ErrorId err);
char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname);
char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname);
@@ -21,8 +23,10 @@ typedef struct Maybe{
Unitype value;
char* errmsg;
} Maybe;
+
// return it if func doesn't return anything
-static const Maybe MaybeNull={.value.type=Null, .value.VoidPtr=NULL,.errmsg=NULL};
+// .value .errmsg
+#define MaybeNull (Maybe){UniNull, NULL}
void Maybe_free(Maybe e);
void printMaybe(Maybe e);
@@ -44,9 +48,12 @@ char* __unknownErr( );
default: __unknownErr\
)(E)
-#define throw(E) __EXIT(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__)))
-#define safethrow(E, FREEMEM) { FREEMEM; __RETURN_EXCEPTION(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))); }
-
+#if __cplusplus
+ #define throw_id(E) __EXIT(((char*)__genErrMsg(errname(E), __FILE__,__LINE__,__func__)))
+ #define throw_msg(E) __EXIT(((char*)__genErrMsg(E, __FILE__,__LINE__,__func__)))
+#else
+ #define throw(E) __EXIT(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__)))
+ #define safethrow(E, FREEMEM) { FREEMEM; __RETURN_EXCEPTION(((char*)__genErrMsg((__stringify_err(E)), __FILE__,__LINE__,__func__))); }
#define try(_funcCall, _rezult, freeMem) Maybe _rezult=_funcCall; if(_rezult.errmsg){\
freeMem;\
@@ -57,7 +64,9 @@ char* __unknownErr( );
#define tryLast(_funcCall, _rezult) Maybe _rezult=_funcCall; if(_rezult.errmsg){\
_rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__);\
__EXIT(_rezult.errmsg);\
- }else
+ }else
+
+#endif
#if __cplusplus
}
diff --git a/base/base.h b/src/base/optime.h
similarity index 88%
rename from base/base.h
rename to src/base/optime.h
index f9d56b8..ea7446c 100644
--- a/base/base.h
+++ b/src/base/optime.h
@@ -1,13 +1,6 @@
#pragma once
-#if __cplusplus
-extern "C" {
-#endif
-
-#include "std.h"
#include "types.h"
-#include "errors.h"
-#include "cptr.h"
// executes codeblock and prints execution time
#ifdef CLOCK_REALTIME // non-standard high-precision clock
@@ -20,7 +13,7 @@ extern "C" {
double t=(double)(stop.tv_sec-start.tv_sec+(double)(stop.tv_nsec-start.tv_nsec)/1000000000)/repeats;\
printf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
})
-#else //
+#else // standard low precision clock
#define optime(opname,repeats,codeblock) ({\
clock_t start=clock();\
for(uint64 ___OPREP=0;___OPREP<(uint64)repeats;___OPREP++)\
@@ -30,7 +23,3 @@ extern "C" {
printf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
})
#endif
-
-#if __cplusplus
-}
-#endif
\ No newline at end of file
diff --git a/base/std.h b/src/base/std.h
similarity index 81%
rename from base/std.h
rename to src/base/std.h
index 4607014..815c63c 100644
--- a/base/std.h
+++ b/src/base/std.h
@@ -12,9 +12,6 @@ extern "C" {
#include
#include
-#define CHOOSE(B, Y, N) __builtin_choose_expr(B, Y, N)
-
-#define IFTYPE(X, T) __builtin_types_compatible_p(typeof(X), T)
#define dbg(N) printf("\e[95m%d\n",N)
@@ -40,13 +37,20 @@ extern "C" {
#ifdef _MSC_VER
#define IFWIN(YES, NO) YES
+ #define IFMSC(YES, NO) YES
+#elif defined(_WIN64) || defined(_WIN32)
+ #define IFWIN(YES, NO) YES
+ #define IFMSC(YES, NO) NO
#elif defined(__GNUC__)
#define IFWIN(YES, NO) NO
+ #define IFMSC(YES, NO) NO
#else
#pragma GCC error "unknown compiler"
#endif
-
+#ifndef NULL
+ #define NULL ((void*)0)
+#endif
#if __cplusplus
}
diff --git a/base/types.c b/src/base/types.c
similarity index 91%
rename from base/types.c
rename to src/base/types.c
index 459ffa5..fed1f0b 100644
--- a/base/types.c
+++ b/src/base/types.c
@@ -41,7 +41,7 @@ const char* my_type_name(my_type t){
case AutoarrUInt64Ptr: return "AutoarrUInt64Ptr";
case AutoarrUnitypePtr: return "AutoarrUnitypePtr";
case AutoarrKVPairPtr: return "AutoarrKVPairPtr";
- default: throw(ERR_WRONGTYPE); return "ERROR";
+ default: throw(ERR_WRONGTYPE);
}
}
@@ -116,7 +116,7 @@ void Unitype_free(Unitype u){
#define BUFSIZE 64
char* sprintuni(Unitype v){
char* buf=malloc(BUFSIZE);
- IFWIN(
+ IFMSC(
switch (v.type) {
case Null: sprintf_s(buf, BUFSIZE, "{Null}");break;
case Float64: sprintf_s(buf, BUFSIZE, "{%s : %lf}", my_type_name(v.type),v.Float64);break;
@@ -131,17 +131,17 @@ char* sprintuni(Unitype v){
default: sprintf_s(buf, BUFSIZE, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
},
switch (v.type) {
- case Null: sprintf(buf, "{Null}");break;
- case Float64: sprintf(buf, "{%s : %lf}", my_type_name(v.type),v.Float64);break;
+ case Null: sprintf(buf, "{Null}"); break;
+ case Float64: sprintf(buf, "{%s : %lf}", my_type_name(v.type),v.Float64); break;
case Bool:
- case UInt64: sprintf(buf, "{%s : %lu}", my_type_name(v.type),v.UInt64);break;
- case Int64: sprintf(buf, "{%s : %ld}", my_type_name(v.type),v.Int64);break;
+ case UInt64: sprintf(buf, "{%s : " IFWIN("%llu", "%lu") "}", my_type_name(v.type),v.UInt64); break;
+ case Int64: sprintf(buf, "{%s : " IFWIN("%lld", "%ld") "}", my_type_name(v.type),v.Int64); break;
case CharPtr: ;
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
buf=realloc(buf, newBUFSIZE);
sprintf(buf, "{%s : \"%s\"}", my_type_name(v.type),(char*)v.VoidPtr);
break;
- default: sprintf(buf, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
+ default: sprintf(buf, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
}
);
return buf;
diff --git a/base/types.h b/src/base/types.h
similarity index 96%
rename from base/types.h
rename to src/base/types.h
index 058e4c0..b6de6ea 100644
--- a/base/types.h
+++ b/src/base/types.h
@@ -26,6 +26,7 @@ typedef enum __attribute__((__packed__)) my_type {
AutoarrInt32Ptr, AutoarrUInt32Ptr, AutoarrInt64Ptr, AutoarrUInt64Ptr,
AutoarrUnitypePtr, AutoarrKVPairPtr
} my_type;
+static const my_type my_type_last=AutoarrKVPairPtr;
const char* my_type_name(my_type t);
diff --git a/tests/main.c b/tests/main.cpp
similarity index 59%
rename from tests/main.c
rename to tests/main.cpp
index 6b3b54b..b480be2 100644
--- a/tests/main.c
+++ b/tests/main.cpp
@@ -1,18 +1,21 @@
#include "tests.h"
void test_all(){
- test_autoarr();
test_string();
test_safethrow();
test_searchtree();
+ test_autoarr();
+ test_hash_functions();
test_hashtable();
test_dtsod();
- printf("\e[96m---------------------------------------\e[0m\n");
+ test_autoarr2();
+ // test_hashtable2();
+ printf("\e[96m--------------------------------------\e[0m\n");
}
int main(){
setlocale(LC_ALL, "en-US.Unicode");
- printf("\e[92mdtsod parser in c language!\e[97m\n");
+ printf("\e[92mkerep tests are starting!\e[97m\n");
optime("test_all",1,test_all());
printf("\e[0m\n");
return 0;
diff --git a/tests/test_autoarr.c b/tests/test_autoarr.c
index c52bfa7..11b818d 100644
--- a/tests/test_autoarr.c
+++ b/tests/test_autoarr.c
@@ -1,5 +1,5 @@
#include "tests.h"
-#include "../Autoarr/Autoarr.h"
+#include "../src/Autoarr/Autoarr.h"
static void printautoarr(Autoarr(uint16)* ar){
printf("\e[94mAutoarr(uint16): "
@@ -48,6 +48,6 @@ void test_autoarr(){
printf("\e[92mautoarr values reset\n");
printallval(ar);
Autoarr_free(ar);
- printf("\e[92mautoarr cleared\n");
+ printf("\e[92mautoarr deleted\n");
}));
}
diff --git a/tests/test_autoarr2.cpp b/tests/test_autoarr2.cpp
new file mode 100644
index 0000000..66af88e
--- /dev/null
+++ b/tests/test_autoarr2.cpp
@@ -0,0 +1,52 @@
+#include "tests.h"
+#include "../src/Autoarr2/Autoarr2.hpp"
+
+
+#define maxlength 160
+
+void printautoarr2(Autoarr2* ar){
+ printf("\e[94mAutoarr2: "
+ IFWIN("%llu", "%lu")
+ "\n blocks_count: %u\n"
+ " max_block_length: %u\n"
+ " block_length: %u\n"
+ " length: %u\n",
+ sizeof(Autoarr2),
+ ar->blocks_count,
+ ar->max_block_length,
+ ar->block_length,
+ ar->length);
+}
+
+void fillar2(Autoarr2* ar){
+ for (uint16 i=0;iadd(i);
+}
+void resetar2(Autoarr2* ar){
+ for (uint16 i=0;iset(i,maxlength-i-1);
+}
+
+void printallval2(Autoarr2* ar){
+ printf("\e[90m");
+ for (uint16 i=0;ilength;i++)
+ printf("%u ",ar->get(i));
+ printf("\n");
+}
+
+void test_autoarr2(){
+ optime("test_autoarr2",1,({
+ printf("\e[96m------------[test_autoarr2]-----------\n");
+ Autoarr2* ar=new Autoarr2(16);
+ printf("\e[92mautoarr2 created\n");
+ fillar2(ar);
+ printf("\e[92mautoarr2 filled up\n");
+ printautoarr2(ar);
+ printallval2(ar);
+ resetar2(ar);
+ printf("\e[92mautoarr2 values reset\n");
+ printallval2(ar);
+ delete ar;
+ printf("\e[92mautoarr2 deleted\n");
+ }));
+}
diff --git a/tests/test_dtsod.c b/tests/test_dtsod.c
index a42a970..317c7da 100644
--- a/tests/test_dtsod.c
+++ b/tests/test_dtsod.c
@@ -1,5 +1,5 @@
#include "tests.h"
-#include "../DtsodParser/DtsodV24.h"
+#include "../src/DtsodParser/DtsodV24.h"
const char text[]=
"list_of_lists: [ [\"sss\"]];"
@@ -33,7 +33,7 @@ void print_dtsod(Hashtable* dtsod){
}
void test_dtsod(){
- optime(__func__,1,({
+ //optime(__func__,1,({
printf("\e[96m-------------[test_dtsod]-------------\n");
Hashtable* dtsod;
char* s;
@@ -61,5 +61,5 @@ void test_dtsod(){
}));
free(s);
- }));
+ //}));
}
\ No newline at end of file
diff --git a/tests/test_hash_functions.c b/tests/test_hash_functions.c
new file mode 100644
index 0000000..10c6aee
--- /dev/null
+++ b/tests/test_hash_functions.c
@@ -0,0 +1,46 @@
+#include "tests.h"
+#include "../src/HashFunctions/hash.h"
+#include "../src/Autoarr/Autoarr.h"
+
+
+#define SPEED_TESTS 100000
+#define COLLISION_TESTS 16000
+
+char data[]="iojihiojopijiugbjmoihftytryfdrh";
+
+#define test_hashfunc(hasht, hashf)({\
+ printf("\e[94mfunction: \e[92m" #hashf "\n");\
+ hasht h=0;\
+ optime("speed test", 1, ({\
+ for(uint32 i=0; i
+
+#define TKey std::shared_ptr
+#define TVal uint64
+#define HT_TYPE Hashtable2
+#define HT_TYPE_NAME "Hashtable2, uint64>"
+
+void print_hashtable(HT_TYPE* ht){
+ printf("\e[94m" HT_TYPE_NAME ": "
+ IFWIN("%llu", "%lu")
+ "\n height: %u\n",
+ sizeof(HT_TYPE),
+ ht->height);
+}
+
+std::shared_ptr genkey(uint32 i){
+ char* key=new char[24];
+ IFMSC(
+ sprintf_s(key,24,"key_%u",i),
+ sprintf(key,"key_%u",i)
+ );
+ dbg(i);
+ return std::shared_ptr(key, [](char* s){ delete[] s;});
+}
+
+void fill(HT_TYPE* ht){
+ for(uint32 i=0;i<260;i++)
+ ht->add(genkey(i), 555666);
+ print_hashtable(ht);
+}
+
+TVal gett(HT_TYPE* ht){
+ TVal u;
+ for(uint32 i=0;i<1000;i++){
+ TKey key=genkey(i);
+ u=ht->get(key);
+ }
+ return u;
+}
+
+
+void test_hashtable2(){
+ //optime("test_hashtable2",1,({
+ printf("\e[96m-----------[test_hashtable2]-----------\n");
+#if STORE_HASHES
+ HT_TYPE* ht=new HT_TYPE(
+ [](TKey k) { return hashs(hash_sdbm32,k.get()); });
+#else
+ HT_TYPE* ht=new HT_TYPE(
+ [](TKey k) -> HT_HASH_T { return hashs(hash_sdbm32,k.get()); },
+ [](TKey k0, TKey k1) -> bool { return cptr_compare(k0.get(), k1.get()); });
+#endif
+ printf("\e[92mhashtable created\n");
+ print_hashtable(ht);
+ optime("fill",1,fill(ht));
+ // TVal r;
+ // optime("get",1,r=gett(ht));
+ // dbg((uint32)r);
+ // print_hashtable(ht);
+ delete ht;
+ printf("\e[92mhashtable deleted\n");
+ //}));
+}
diff --git a/tests/test_marshalling.c b/tests/test_marshalling.c
index 6e5017b..3dde3c0 100644
--- a/tests/test_marshalling.c
+++ b/tests/test_marshalling.c
@@ -1,4 +1,4 @@
-#include "../Hashtable/KeyValuePair.h"
+#include "../src/Hashtable/KeyValuePair.h"
EXPORT void CALL test_marshalling(char* text, KVPair** kptr){
KVPair* k=malloc(sizeof(KVPair));
diff --git a/tests/test_safethrow.c b/tests/test_safethrow.c
index 98fc566..4ccd4dc 100644
--- a/tests/test_safethrow.c
+++ b/tests/test_safethrow.c
@@ -21,7 +21,6 @@ Maybe test_maybe(){
try(throw_error(),rez1,;)
printMaybe(rez1);
throw("test_maybe failed");
- return MaybeNull;
}
diff --git a/tests/test_searchtree.c b/tests/test_searchtree.c
index a94bb06..2cb24a1 100644
--- a/tests/test_searchtree.c
+++ b/tests/test_searchtree.c
@@ -1,5 +1,5 @@
#include "tests.h"
-#include "../SearchTree/SearchTree.h"
+#include "../src/SearchTree/SearchTree.h"
void printstnode(STNode* node){
printf("\e[94mSTNode: "
@@ -47,7 +47,7 @@ void test_searchtree(){
printuni(u);
ST_push(node,"message_id", u);
printf(" -> message_id\n ");
- u=(Unitype){.type=Int8Ptr,.VoidPtr=malloc(1)};
+ u=(Unitype){.type=CharPtr,.VoidPtr=cptr_copy("some text UwU")};
printuni(u);
ST_push(node,"text", u);
printf(" -> text\n");
diff --git a/tests/test_string.c b/tests/test_string.c
index 90110f6..047f84d 100644
--- a/tests/test_string.c
+++ b/tests/test_string.c
@@ -1,5 +1,5 @@
#include "tests.h"
-#include "../String/string.h"
+#include "../src/String/string.h"
void test_string(){
optime(__func__,1,({
diff --git a/tests/tests.h b/tests/tests.h
index edaa49f..fb0be11 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -1,12 +1,21 @@
#pragma once
-#include "../base/base.h"
+#include "../src/base/base.h"
-void printuni(Unitype v);
+#if __cplusplus
+extern "C" {
+#endif
+void test_string();
+void test_safethrow();
void test_searchtree();
void test_autoarr();
+void test_autoarr2();
+void test_hash_functions();
void test_hashtable();
-void test_string();
+void test_hashtable2();
void test_dtsod();
-void test_safethrow();
\ No newline at end of file
+
+#if __cplusplus
+}
+#endif
\ No newline at end of file