Merge branch 'rewriting_to_cpp'
This commit is contained in:
commit
8dd6e49269
9
.gitignore
vendored
9
.gitignore
vendored
@ -2,13 +2,12 @@
|
||||
bin/
|
||||
obj/
|
||||
|
||||
# IDE files
|
||||
# user files
|
||||
.old*/
|
||||
.vs/
|
||||
.vscode/
|
||||
.vshistory/
|
||||
.idea/
|
||||
.editorconfig
|
||||
*.user
|
||||
|
||||
#backups
|
||||
.old*/
|
||||
*.vcxproj.filters
|
||||
.config
|
||||
|
||||
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -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
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
8
.idea/customTargets.xml
Normal file
8
.idea/customTargets.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CLionExternalBuildManager">
|
||||
<target id="67054554-5381-4cd7-a829-42719335ecb2" name="test" defaultType="MAKE">
|
||||
<configuration id="5bcf7815-3a13-43ba-8bab-ca1ed444708d" name="test" />
|
||||
</target>
|
||||
</component>
|
||||
</project>
|
||||
29
.idea/inspectionProfiles/Project_Default.xml
Normal file
29
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="clangTidyCheckOptions">
|
||||
<list>
|
||||
<ClangTidyCheckOption />
|
||||
</list>
|
||||
</option>
|
||||
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-not-null-terminated-result,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memory-comparison,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,modernize-avoid-bind,modernize-concat-nested-namespaces,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nodiscard,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-uncaught-exceptions,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ClangdErrorsAndWarnings" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="EmptyDeclOrStmt" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="GrazieInspection" enabled="false" level="TYPO" enabled_by_default="false" />
|
||||
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="Misra" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="myMisraCPPChecks" value="clion-misra-cpp2008-*,-clion-misra-cpp2008-11-0-1" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="OCUnusedGlobalDeclaration" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="ShellCheck" enabled="false" level="ERROR" enabled_by_default="false">
|
||||
<shellcheck_settings value="SC2034,SC2035,SC2059,SC2061,SC2091,SC2155" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
30
.idea/misc.xml
Normal file
30
.idea/misc.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CidrRootsConfiguration">
|
||||
<sourceRoots>
|
||||
<file path="$PROJECT_DIR$/src" />
|
||||
<file path="$PROJECT_DIR$/tests" />
|
||||
</sourceRoots>
|
||||
<excludeRoots>
|
||||
<file path="$PROJECT_DIR$/.vscode" />
|
||||
</excludeRoots>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MakefileSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<MakefileProjectSettings>
|
||||
<option name="buildOptions" value=" " />
|
||||
<option name="buildTarget" value="" />
|
||||
<option name="cleanTarget" value="" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="version" value="2" />
|
||||
</MakefileProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
</project>
|
||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -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);
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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
|
||||
62
Makefile
62
Makefile
@ -1,58 +1,18 @@
|
||||
SRC=$(wildcard [^tests]**/*.c)
|
||||
TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c)
|
||||
|
||||
OUTDIR=bin
|
||||
CMP=gcc
|
||||
OPT_ARGS=-O2 -flto
|
||||
WARN_ARGS=-Wall -Wno-discarded-qualifiers -std=c17
|
||||
|
||||
all: clear_c clear_bin build_test build_lib
|
||||
|
||||
clear_c:
|
||||
clear
|
||||
|
||||
clear_bin:
|
||||
@echo -e '\n\e[96m-------------[clear_bin]--------------\e[0m'
|
||||
rm -rf $(OUTDIR)
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
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)
|
||||
|
||||
###### Building tasks #######
|
||||
build_test:
|
||||
@echo -e '\n\e[96m-------------[build_test]-------------\e[0m'
|
||||
$(CMP) $(OPT_ARGS) $(TEST_ARGS)
|
||||
@build_scripts/build_test.sh
|
||||
|
||||
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_scripts/build_test_dbg.sh
|
||||
|
||||
build_lib:
|
||||
@echo -e '\n\e[96m-------------[build_lib]--------------\e[0m'
|
||||
$(CMP) $(LIB_ARGS) -o $(OUTDIR)/$(LIB_FILE)
|
||||
@build_scripts/build_lib.sh
|
||||
|
||||
######################################
|
||||
###### Run tasks #######
|
||||
######################################
|
||||
test: clear_c build_test
|
||||
@echo -e '\n\e[96m-------------[build_test]-------------\e[0m'
|
||||
tabs 4
|
||||
$(OUTDIR)/$(TEST_FILE)
|
||||
###### Testing tasks #######
|
||||
test: build_test
|
||||
@build_scripts/test.sh
|
||||
|
||||
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
|
||||
test_valgrind: build_test_dbg
|
||||
@build_scripts/test_valgrind.sh
|
||||
|
||||
all: build_test
|
||||
|
||||
10
build_scripts/build_lib.sh
Normal file
10
build_scripts/build_lib.sh
Normal file
@ -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"
|
||||
10
build_scripts/build_test.sh
Normal file
10
build_scripts/build_test.sh
Normal file
@ -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
|
||||
10
build_scripts/build_test_dbg.sh
Normal file
10
build_scripts/build_test_dbg.sh
Normal file
@ -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
|
||||
11
build_scripts/colors.sh
Normal file
11
build_scripts/colors.sh
Normal file
@ -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'
|
||||
33
build_scripts/default.config.sh
Normal file
33
build_scripts/default.config.sh
Normal file
@ -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=""
|
||||
72
build_scripts/functions.sh
Normal file
72
build_scripts/functions.sh
Normal file
@ -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
|
||||
}
|
||||
23
build_scripts/init.sh
Normal file
23
build_scripts/init.sh
Normal file
@ -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
|
||||
8
build_scripts/test.sh
Normal file
8
build_scripts/test.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source build_scripts/init.sh
|
||||
|
||||
print "${CYAN}================[test]================\n"
|
||||
cd $OUTDIR
|
||||
./$TEST_FILE
|
||||
cd ..
|
||||
9
build_scripts/test_valgrind.sh
Normal file
9
build_scripts/test_valgrind.sh
Normal file
@ -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 ..
|
||||
107
kerep.vcxproj
107
kerep.vcxproj
@ -18,6 +18,58 @@
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Autoarr\Autoarr.c" />
|
||||
<ClCompile Include="src\Autoarr\Autoarr_KVPair_exported.c" />
|
||||
<ClCompile Include="src\Autoarr\Autoarr_Unitype_exported.c" />
|
||||
<ClCompile Include="src\base\cptr.c" />
|
||||
<ClCompile Include="src\base\errors.c" />
|
||||
<ClCompile Include="src\base\types.c" />
|
||||
<ClCompile Include="src\DtsodParser\DtsodV24.c" />
|
||||
<ClCompile Include="src\DtsodParser\DtsodV24_deserialize.c" />
|
||||
<ClCompile Include="src\DtsodParser\DtsodV24_exported.c" />
|
||||
<ClCompile Include="src\DtsodParser\DtsodV24_serialize.c" />
|
||||
<ClCompile Include="src\HashFunctions\hash.c" />
|
||||
<ClCompile Include="src\Hashtable\Hashtable.c" />
|
||||
<ClCompile Include="src\Hashtable\KeyValuePair.c" />
|
||||
<ClCompile Include="src\Network\knSocket.c" />
|
||||
<ClCompile Include="src\SearchTree\SearchTree.c" />
|
||||
<ClCompile Include="src\String\string.c" />
|
||||
<ClCompile Include="src\String\StringBuilder.c" />
|
||||
<ClCompile Include="tests\main.cpp" />
|
||||
<ClCompile Include="tests\test_autoarr.c" />
|
||||
<ClCompile Include="tests\test_autoarr2.cpp" />
|
||||
<ClCompile Include="tests\test_dtsod.c" />
|
||||
<ClCompile Include="tests\test_hashtable.c" />
|
||||
<ClCompile Include="tests\test_hashtable2.cpp" />
|
||||
<ClCompile Include="tests\test_hash_functions.c" />
|
||||
<ClCompile Include="tests\test_marshalling.c" />
|
||||
<ClCompile Include="tests\test_safethrow.c" />
|
||||
<ClCompile Include="tests\test_searchtree.c" />
|
||||
<ClCompile Include="tests\test_string.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Autoarr2\Autoarr2.hpp" />
|
||||
<ClInclude Include="src\Autoarr\Autoarr.h" />
|
||||
<ClInclude Include="src\Autoarr\Autoarr_declare.h" />
|
||||
<ClInclude Include="src\Autoarr\Autoarr_define.h" />
|
||||
<ClInclude Include="src\base\base.h" />
|
||||
<ClInclude Include="src\base\cptr.h" />
|
||||
<ClInclude Include="src\base\errors.h" />
|
||||
<ClInclude Include="src\base\optime.h" />
|
||||
<ClInclude Include="src\base\std.h" />
|
||||
<ClInclude Include="src\base\types.h" />
|
||||
<ClInclude Include="src\DtsodParser\DtsodV24.h" />
|
||||
<ClInclude Include="src\HashFunctions\hash.h" />
|
||||
<ClInclude Include="src\Hashtable2\Hashtable2.hpp" />
|
||||
<ClInclude Include="src\Hashtable\Hashtable.h" />
|
||||
<ClInclude Include="src\Hashtable\KeyValuePair.h" />
|
||||
<ClInclude Include="src\Network\network.h" />
|
||||
<ClInclude Include="src\SearchTree\SearchTree.h" />
|
||||
<ClInclude Include="src\String\string.h" />
|
||||
<ClInclude Include="src\String\StringBuilder.h" />
|
||||
<ClInclude Include="tests\tests.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@ -112,7 +164,7 @@
|
||||
<PrecompiledHeaderOutputFile />
|
||||
<AdditionalOptions>/Zc:twoPhase- /MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
<Optimization>Disabled</Optimization>
|
||||
</ClCompile>
|
||||
@ -139,7 +191,7 @@
|
||||
<AdditionalOptions>/Zc:twoPhase- /MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -164,7 +216,7 @@
|
||||
<PrecompiledHeaderOutputFile />
|
||||
<AdditionalOptions>/Zc:twoPhase- /MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -184,13 +236,13 @@
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<PrecompiledHeaderOutputFile />
|
||||
<AdditionalOptions>/Zc:twoPhase- /MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -201,51 +253,6 @@
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Autoarr\Autoarr.h" />
|
||||
<ClInclude Include="Autoarr\Autoarr_declare.h" />
|
||||
<ClInclude Include="Autoarr\Autoarr_define.h" />
|
||||
<ClInclude Include="base\base.h" />
|
||||
<ClInclude Include="base\errors.h" />
|
||||
<ClInclude Include="base\cptr.h" />
|
||||
<ClInclude Include="base\std.h" />
|
||||
<ClInclude Include="base\types.h" />
|
||||
<ClInclude Include="DtsodParser\DtsodV24.h" />
|
||||
<ClInclude Include="Hashtable\hash.h" />
|
||||
<ClInclude Include="Hashtable\Hashtable.h" />
|
||||
<ClInclude Include="Hashtable\KeyValuePair.h" />
|
||||
<ClInclude Include="SearchTree\SearchTree.h" />
|
||||
<ClInclude Include="String\string.h" />
|
||||
<ClInclude Include="String\StringBuilder.h" />
|
||||
<ClInclude Include="tests\tests.h" />
|
||||
<ClInclude Include="tests\test_marshalling.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Autoarr\Autoarr.c" />
|
||||
<ClCompile Include="Autoarr\Autoarr_KVPair_exported.c" />
|
||||
<ClCompile Include="Autoarr\Autoarr_Unitype_exported.c" />
|
||||
<ClCompile Include="base\cptr.c" />
|
||||
<ClCompile Include="base\errors.c" />
|
||||
<ClCompile Include="base\types.c" />
|
||||
<ClCompile Include="DtsodParser\DtsodV24.c" />
|
||||
<ClCompile Include="DtsodParser\DtsodV24_deserialize.c" />
|
||||
<ClCompile Include="DtsodParser\DtsodV24_exported.c" />
|
||||
<ClCompile Include="DtsodParser\DtsodV24_serialize.c" />
|
||||
<ClCompile Include="Hashtable\hash.c" />
|
||||
<ClCompile Include="Hashtable\Hashtable.c" />
|
||||
<ClCompile Include="Hashtable\KeyValuePair.c" />
|
||||
<ClCompile Include="SearchTree\SearchTree.c" />
|
||||
<ClCompile Include="String\string.c" />
|
||||
<ClCompile Include="String\StringBuilder.c" />
|
||||
<ClCompile Include="tests\main.c" />
|
||||
<ClCompile Include="tests\test_autoarr.c" />
|
||||
<ClCompile Include="tests\test_dtsod.c" />
|
||||
<ClCompile Include="tests\test_hashtable.c" />
|
||||
<ClCompile Include="tests\test_marshalling.c" />
|
||||
<ClCompile Include="tests\test_safethrow.c" />
|
||||
<ClCompile Include="tests\test_searchtree.c" />
|
||||
<ClCompile Include="tests\test_string.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
||||
@ -1,144 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Исходные файлы">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы заголовков">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Autoarr\Autoarr.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Autoarr\Autoarr_declare.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Autoarr\Autoarr_define.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\base.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\errors.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\cptr.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\std.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\types.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DtsodParser\DtsodV24.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Hashtable\hash.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Hashtable\Hashtable.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Hashtable\KeyValuePair.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SearchTree\SearchTree.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\test_marshalling.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\tests.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="String\string.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="String\StringBuilder.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Autoarr\Autoarr.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="base\errors.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="base\types.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DtsodParser\DtsodV24.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DtsodParser\DtsodV24_deserialize.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DtsodParser\DtsodV24_serialize.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Hashtable\hash.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Hashtable\Hashtable.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Hashtable\KeyValuePair.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SearchTree\SearchTree.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\main.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_autoarr.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_dtsod.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_hashtable.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_searchtree.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_string.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_marshalling.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DtsodParser\DtsodV24_exported.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Autoarr\Autoarr_KVPair_exported.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Autoarr\Autoarr_Unitype_exported.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\test_safethrow.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="base\cptr.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="String\string.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="String\StringBuilder.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
19
src/Autoarr/Autoarr.c
Normal file
19
src/Autoarr/Autoarr.c
Normal file
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
@ -6,7 +6,7 @@ extern "C" {
|
||||
|
||||
#include "../base/base.h"
|
||||
|
||||
#define declare_Autoarr(type)\
|
||||
#define Autoarr_declare(type)\
|
||||
\
|
||||
struct Autoarr_##type;\
|
||||
\
|
||||
@ -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){\
|
||||
122
src/Autoarr2/Autoarr2.hpp
Normal file
122
src/Autoarr2/Autoarr2.hpp
Normal file
@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include "../base/base.h"
|
||||
|
||||
#define __AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT 64
|
||||
#define Autoarr2_NO_REZULT (uint32)-1
|
||||
|
||||
|
||||
template<typename T>
|
||||
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 <value> inclusion
|
||||
// using <cmpf> to compare values
|
||||
template<class cmp_func_lambda>
|
||||
uint32 search(T& value, cmp_func_lambda cmpf, uint32 fromIndex, uint32 toIndex);
|
||||
template<class cmp_func_lambda>
|
||||
uint32 search(T& value, cmp_func_lambda cmpf, uint32 fromIndex);
|
||||
template<class cmp_func_lambda>
|
||||
uint32 search(T& value, cmp_func_lambda cmpf);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::Autoarr2(uint16 _max_block_length) {
|
||||
values = NULL;
|
||||
block_length = 0;
|
||||
blocks_count = 0;
|
||||
length = 0;
|
||||
max_block_length=_max_block_length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::Autoarr2() : Autoarr2(__AUTOARR2_MAX_BLOCK_LENGTH_DEFAULT) {}
|
||||
|
||||
template<typename T>
|
||||
Autoarr2<T>::~Autoarr2() {
|
||||
for (uint16 i=0;i<blocks_count;i++)
|
||||
delete[] values[i];
|
||||
delete[] values;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
T *Autoarr2<T>::getptr(uint32 index) {
|
||||
if(index>=length) throw_id(ERR_WRONGINDEX);
|
||||
return values[index/max_block_length]+index%max_block_length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Autoarr2<T>::get(uint32 index) {
|
||||
return *getptr(index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::set(uint32 index, T value) {
|
||||
*getptr(index)=value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::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<blocks_count;i++)
|
||||
new_values[i]=values[i];
|
||||
new_values[blocks_count]=new T[max_block_length];
|
||||
delete[] values;
|
||||
values=new_values;
|
||||
blocks_count++;
|
||||
}
|
||||
|
||||
values[blocks_count-1][block_length]=value;
|
||||
block_length++;
|
||||
length++;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<class cmp_func_lambda>
|
||||
uint32 Autoarr2<T>::search(T& value, cmp_func_lambda cmpf, uint32 fromIndex, uint32 toIndex){
|
||||
uint32 index=fromIndex;
|
||||
for(; index<toIndex; index++)
|
||||
if(cmpf(value,get(index)))
|
||||
return index;
|
||||
return Autoarr2_NO_REZULT;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<class cmp_func_lambda>
|
||||
uint32 Autoarr2<T>::search(T& value, cmp_func_lambda cmpf, uint32 fromIndex){
|
||||
return search(value, cmpf, fromIndex, length);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<class cmp_func_lambda>
|
||||
uint32 Autoarr2<T>::search(T& value, cmp_func_lambda cmpf){
|
||||
return search(value, cmpf, 0, length);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Autoarr2<T>::remove(uint32 index){
|
||||
throw_id(ERR_NOTIMPLEMENTED);
|
||||
}
|
||||
@ -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;
|
||||
@ -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');
|
||||
111
src/HashFunctions/hash.c
Normal file
111
src/HashFunctions/hash.c
Normal file
@ -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;
|
||||
// }
|
||||
17
src/HashFunctions/hash.h
Normal file
17
src/HashFunctions/hash.h
Normal file
@ -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
|
||||
@ -37,14 +37,12 @@ void Hashtable_expand(Hashtable* ht){
|
||||
for(uint16 i=0;i<HT_HEIGHTS[ht->hein-1];i++){
|
||||
Autoarr(KVPair)* ar=ht->rows[i];
|
||||
uint32 arlen=Autoarr_length(ar);
|
||||
for(uint16 k=0;k<arlen;k++){
|
||||
for(uint32 k=0;k<arlen;k++){
|
||||
KVPair p=Autoarr_get(ar,k);
|
||||
uint16 newrown=hash32(p.key)%HT_HEIGHTS[ht->hein];
|
||||
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;
|
||||
}
|
||||
@ -4,8 +4,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "hash.h"
|
||||
#include "../HashFunctions/hash.h"
|
||||
#include "KeyValuePair.h"
|
||||
|
||||
typedef struct Hashtable{
|
||||
@ -1,6 +1,6 @@
|
||||
#include "KeyValuePair.h"
|
||||
|
||||
define_Autoarr(KVPair)
|
||||
Autoarr_define(KVPair)
|
||||
|
||||
|
||||
// proper way to clear a KVP
|
||||
@ -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);
|
||||
209
src/Hashtable2/Hashtable2.hpp
Normal file
209
src/Hashtable2/Hashtable2.hpp
Normal file
@ -0,0 +1,209 @@
|
||||
#pragma once
|
||||
|
||||
#include "../HashFunctions/hash.h"
|
||||
#include "../Autoarr2/Autoarr2.hpp"
|
||||
#include <functional>
|
||||
|
||||
// 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<typename TKey, typename TVal>
|
||||
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<HT_HASH_T(TKey)>;
|
||||
using KeyCmpFunc_t=std::function<bool(TKey, TKey)>;
|
||||
|
||||
// fields
|
||||
Autoarr2<KeyValue>** 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<typename TKey, typename TVal>
|
||||
Hashtable2<TKey, TVal>::Hashtable2(HashKeyFunc_t _hashKeyFunc){
|
||||
hashKeyFunc=_hashKeyFunc;
|
||||
hein=_HT_HEIN_MIN;
|
||||
height=HT_HEIGHTS[hein];
|
||||
rows=new Autoarr2<KeyValue>*[height];
|
||||
for(HT_HEIGHT_T i=0; i<height; i++)
|
||||
rows[i]=new Autoarr2<KeyValue>(_HT_ARR_BL);
|
||||
}
|
||||
|
||||
#if !STORE_HASHES
|
||||
template<typename TKey, typename TVal>
|
||||
Hashtable2<TKey, TVal>::Hashtable2(HashKeyFunc_t _hashKeyFunc, KeyCmpFunc_t _keyComparFunc) : Hashtable2(_hashKeyFunc) {
|
||||
keyComparFunc=_keyComparFunc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
void Hashtable2<TKey, TVal>::free_rows(){
|
||||
for(uint32 i=0; i< height; i++)
|
||||
delete rows[i];
|
||||
delete[] rows;
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
Hashtable2<TKey, TVal>::~Hashtable2() { free_rows(); }
|
||||
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
TVal* Hashtable2<TKey, TVal>::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<typename TKey, typename TVal>
|
||||
TVal* Hashtable2<TKey, TVal>::getptr(TKey key){
|
||||
HT_HASH_T keyHash;
|
||||
HT_HEIGHT_T rowN;
|
||||
return getptr(key, keyHash, rowN);
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
TVal Hashtable2<TKey, TVal>::get(TKey key){
|
||||
TVal* ptr=getptr(key);
|
||||
if(!ptr)
|
||||
throw_id(ERR_KEYNOTFOUND);
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
bool Hashtable2<TKey, TVal>::tryGet(TKey key, TVal* output){
|
||||
TVal* ptr=getptr(key);
|
||||
if(!ptr)
|
||||
return false;
|
||||
*output=*ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
void Hashtable2<TKey, TVal>::expand(){
|
||||
printf("expand\n"); fflush(stdout);
|
||||
if(hein>=_HT_HEIN_MAX)
|
||||
throw_id(ERR_MAXLENGTH);
|
||||
|
||||
uint32 newHeight=HT_HEIGHTS[++hein];
|
||||
Autoarr2<KeyValue>** newRows=new Autoarr2<KeyValue>*[newHeight];
|
||||
for(HT_HEIGHT_T i=0; i<newHeight; i++)
|
||||
newRows[i]=new Autoarr2<KeyValue>(_HT_ARR_BL);
|
||||
|
||||
for(HT_HEIGHT_T oldRowN=0; oldRowN<height; oldRowN++)
|
||||
for(uint32 k=0; k < rows[oldRowN]->length; 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<typename TKey, typename TVal>
|
||||
void Hashtable2<TKey, TVal>::add(TKey& key, TVal& value, HT_HASH_T keyHash, HT_HEIGHT_T rowN){
|
||||
printf("add\n"); fflush(stdout);
|
||||
Autoarr2<KeyValue>* 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<typename TKey, typename TVal>
|
||||
void Hashtable2<TKey, TVal>::add(TKey key, TVal value){
|
||||
HT_HASH_T keyHash=hashKeyFunc(key);
|
||||
HT_HEIGHT_T rowN=keyHash%height;
|
||||
add(key, value, keyHash, rowN);
|
||||
}
|
||||
|
||||
template<typename TKey, typename TVal>
|
||||
void Hashtable2<TKey, TVal>::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<typename TKey, typename TVal>
|
||||
void Hashtable2<TKey, TVal>::remove(TKey key){
|
||||
throw_id(ERR_NOTIMPLEMENTED);
|
||||
}
|
||||
1
src/Network/knSocket.c
Normal file
1
src/Network/knSocket.c
Normal file
@ -0,0 +1 @@
|
||||
#include "network.h"
|
||||
43
src/Network/network.h
Normal file
43
src/Network/network.h
Normal file
@ -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 <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#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
|
||||
@ -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;
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -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)
|
||||
);
|
||||
@ -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;
|
||||
@ -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){
|
||||
15
src/base/base.h
Normal file
15
src/base/base.h
Normal file
@ -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
|
||||
@ -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;
|
||||
}
|
||||
@ -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";}
|
||||
@ -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;\
|
||||
@ -59,6 +66,8 @@ char* __unknownErr( );
|
||||
__EXIT(_rezult.errmsg);\
|
||||
}else
|
||||
|
||||
#endif
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -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
|
||||
@ -12,9 +12,6 @@ extern "C" {
|
||||
#include <time.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#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
|
||||
}
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
@ -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");
|
||||
}));
|
||||
}
|
||||
|
||||
52
tests/test_autoarr2.cpp
Normal file
52
tests/test_autoarr2.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "tests.h"
|
||||
#include "../src/Autoarr2/Autoarr2.hpp"
|
||||
|
||||
|
||||
#define maxlength 160
|
||||
|
||||
void printautoarr2(Autoarr2<uint16>* ar){
|
||||
printf("\e[94mAutoarr2<uint16>: "
|
||||
IFWIN("%llu", "%lu")
|
||||
"\n blocks_count: %u\n"
|
||||
" max_block_length: %u\n"
|
||||
" block_length: %u\n"
|
||||
" length: %u\n",
|
||||
sizeof(Autoarr2<uint16>),
|
||||
ar->blocks_count,
|
||||
ar->max_block_length,
|
||||
ar->block_length,
|
||||
ar->length);
|
||||
}
|
||||
|
||||
void fillar2(Autoarr2<uint16>* ar){
|
||||
for (uint16 i=0;i<maxlength;i++)
|
||||
ar->add(i);
|
||||
}
|
||||
void resetar2(Autoarr2<uint16>* ar){
|
||||
for (uint16 i=0;i<maxlength;i++)
|
||||
ar->set(i,maxlength-i-1);
|
||||
}
|
||||
|
||||
void printallval2(Autoarr2<uint16>* ar){
|
||||
printf("\e[90m");
|
||||
for (uint16 i=0;i<ar->length;i++)
|
||||
printf("%u ",ar->get(i));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void test_autoarr2(){
|
||||
optime("test_autoarr2",1,({
|
||||
printf("\e[96m------------[test_autoarr2]-----------\n");
|
||||
Autoarr2<uint16>* ar=new Autoarr2<uint16>(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");
|
||||
}));
|
||||
}
|
||||
@ -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);
|
||||
}));
|
||||
//}));
|
||||
}
|
||||
46
tests/test_hash_functions.c
Normal file
46
tests/test_hash_functions.c
Normal file
@ -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<SPEED_TESTS; i++)\
|
||||
h=hashf(h, data, sizeof(data));\
|
||||
}));\
|
||||
/*printf("\e[94mhash of \"\e[90m%s\e[94m\": \e[92m%x\n",data, h);*/\
|
||||
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
|
||||
optime("collision test",1,({\
|
||||
uint32 collisions=0;\
|
||||
for(uint64 i=0;i< COLLISION_TESTS;i++){\
|
||||
hasht h=hashb(hashf, (uint8*)&i, sizeof(i));\
|
||||
bool col=false;\
|
||||
Autoarr_foreach(hashes,e,({\
|
||||
if(e==h) {\
|
||||
col=true;\
|
||||
break;\
|
||||
}\
|
||||
}));\
|
||||
if(col) collisions++;\
|
||||
else Autoarr_add(hashes,h);\
|
||||
}\
|
||||
printf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, COLLISION_TESTS);\
|
||||
}));\
|
||||
Autoarr_free(hashes);\
|
||||
printf("\e[96m--------------------------------------\n");\
|
||||
})
|
||||
|
||||
void test_hash_functions(){
|
||||
optime("test_hash_functions",1,({
|
||||
printf("\e[96m--------[test_hash_functions]---------\n");
|
||||
test_hashfunc(uint32, hash_crc32);
|
||||
test_hashfunc(uint32, hash_sdbm32);
|
||||
}));
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
#include "tests.h"
|
||||
#include "../Hashtable/Hashtable.h"
|
||||
#include "../src/Hashtable/Hashtable.h"
|
||||
|
||||
void print_hashtable(Hashtable* ht){
|
||||
printf("\e[94mHashtable: "
|
||||
@ -38,7 +38,7 @@ void printrowgraph(Hashtable* ht){
|
||||
|
||||
char* genkey(uint32 i){
|
||||
char* key=malloc(12);
|
||||
IFWIN(
|
||||
IFMSC(
|
||||
sprintf_s(key,12,"key_%u",i),
|
||||
sprintf(key,"key_%u",i)
|
||||
);
|
||||
|
||||
65
tests/test_hashtable2.cpp
Normal file
65
tests/test_hashtable2.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "tests.h"
|
||||
#include "../src/Hashtable2/Hashtable2.hpp"
|
||||
#include <memory>
|
||||
|
||||
#define TKey std::shared_ptr<char>
|
||||
#define TVal uint64
|
||||
#define HT_TYPE Hashtable2<TKey, TVal>
|
||||
#define HT_TYPE_NAME "Hashtable2<std::shared_ptr<char*>, 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<char> 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<char>(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");
|
||||
//}));
|
||||
}
|
||||
@ -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));
|
||||
|
||||
@ -21,7 +21,6 @@ Maybe test_maybe(){
|
||||
try(throw_error(),rez1,;)
|
||||
printMaybe(rez1);
|
||||
throw("test_maybe failed");
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "tests.h"
|
||||
#include "../String/string.h"
|
||||
#include "../src/String/string.h"
|
||||
|
||||
void test_string(){
|
||||
optime(__func__,1,({
|
||||
|
||||
@ -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();
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user