diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f579a1f..3ece238 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,14 @@ FROM mcr.microsoft.com/devcontainers/cpp:0-ubuntu-22.04 +# LIST: https://mcr.microsoft.com/v2/vscode/devcontainers/cpp/tags/list + +# command 'add-apt-repository' +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends software-properties-common + +# see: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test +# RUN sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + +# =========== ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" @@ -6,9 +16,9 @@ ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" COPY ./reinstall-cmake.sh /tmp/ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ - chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ - fi \ - && rm -f /tmp/reinstall-cmake.sh + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh # [Optional] Uncomment this section to install additional vcpkg ports. # RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore index 89ccd6f..4f92a74 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ app_* a.out build/* compile_commands.* +tmp* +.vscode/ ### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor # Ignore the `external` link (that is added by `bazel-compile-commands-extractor`). The link differs between macOS/Linux and Windows, so it shouldn't be checked in. The pattern must not end with a trailing `/` because it's a symlink on macOS/Linux. /external diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 80058bb..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [], - "compilerPath": "/usr/bin/clang-12", - "cStandard": "c17", - "cppStandard": "c++20", - "intelliSenseMode": "linux-clang-x64", - "configurationProvider": "ms-vscode.makefile-tools" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 77558dd..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [ - "" - ], - "stopAtEntry": false, - "cwd": "/home/imcoelho/git-reps/cycles", - "environment": [], - "program": "/home/imcoelho/git-reps/cycles/build/Debug/outDebug", - "internalConsoleOptions": "openOnSessionStart", - "MIMode": "gdb", - "miDebuggerPath": "/usr/bin/gdb", - "externalConsole": false, - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 35713e0..4f089c3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,12 +7,14 @@ "-log=verbose", "-pretty", "--background-index", - "--compile-commands-dir=/workspaces/cycles/", + "--compile-commands-dir=/workspaces/cycles/build/", + // "--compile-commands-dir=/workspaces/cycles/", ], "C_Cpp.intelliSenseEngine": "Disabled", "testMate.cpp.test.advancedExecutables": [ { - "pattern": "{bazel-bin}/**/*{test}*" + //"pattern": "{bazel-bin}/**/*{test}*" + "pattern": "{build}/**/*{test}*" } ], "C_Cpp.codeAnalysis.clangTidy.useBuildPath": true, @@ -70,5 +72,6 @@ "iterator": "cpp", "queue": "cpp", "random": "cpp" - } + }, + "cmake.sourceDirectory": "${workspaceFolder}/." } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..06e9cc3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.22) +project(cycles-project LANGUAGES CXX VERSION 0.0.1) +# +set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_STANDARD_REQUIRED ON) +set (CMAKE_EXPORT_COMPILE_COMMANDS ON) +Include(FetchContent) + +# =================== +# header only library +# ------------------- +add_library(cycles INTERFACE) +target_include_directories(cycles INTERFACE include/) +# +add_subdirectory(examples) +# +add_subdirectory(tests) diff --git a/Makefile b/Makefile index d0468b0..a9f00eb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: test demo demo: - cd src/demo_cptr && make + cd examples/demo_cptr && make test: cd tests && make @@ -12,5 +12,5 @@ bench: clean: rm -f vgcore.* rm -f tests/vgcore.* - rm -f src/demo_cptr/vgcore.* - rm -f src/examples/vgcore.* \ No newline at end of file + rm -f examples/demo_cptr/vgcore.* + rm -f examples/examples/vgcore.* \ No newline at end of file diff --git a/README.md b/README.md index 4856091..3dc4a1d 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,8 @@ This project can be used to manage cyclic data structures with memory safe. See https://github.com/hsutter/gcpp and its video from cppcon 2016 [Leak Freedom in C++... by Default](https://www.youtube.com/watch?v=JfmTagWcqoE). +Other related project is sgcl/tracked_ptr: https://github.com/pebal/sgcl + ## Acknowledgements We appreciate the interest of all involved in this project. diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index 72dfe80..0000000 --- a/build/.gitignore +++ /dev/null @@ -1 +0,0 @@ -app_* \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..9d7cbd2 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,17 @@ + +# +add_executable(example1 basic_examples/app_example1.cpp) +target_link_libraries(example1 PRIVATE cycles) + +add_executable(example2 basic_examples/app_example2.cpp) +target_link_libraries(example2 PRIVATE cycles) + +add_executable(example3 basic_examples/app_example3.cpp) +target_link_libraries(example3 PRIVATE cycles) + +add_executable(demo demo_cptr/demo.cpp) +target_link_libraries(demo PRIVATE cycles) + +add_executable(demo0_cycles_test_graph demo_cptr/demo0_cycles_test_graph.cpp) +target_link_libraries(demo0_cycles_test_graph PRIVATE cycles) + diff --git a/src/examples/.gitignore b/examples/basic_examples/.gitignore similarity index 100% rename from src/examples/.gitignore rename to examples/basic_examples/.gitignore diff --git a/src/examples/makefile b/examples/basic_examples/makefile similarity index 52% rename from src/examples/makefile rename to examples/basic_examples/makefile index 9da0318..0b36d72 100644 --- a/src/examples/makefile +++ b/examples/basic_examples/makefile @@ -1,13 +1,13 @@ all: app_example1 app_example2 app_example3 app_example1: app_example1.cpp - g++ app_example1.cpp -I../../include/ -I../../src/ -Wfatal-errors -g -std=c++17 -o ../../build/app_example1 + g++ app_example1.cpp -I../../include/ -I../../examples/ -Wfatal-errors -g -std=c++17 -o ../../build/app_example1 app_example2: app_example2.cpp - g++ app_example2.cpp -I../../include/ -I../../src/ -Wfatal-errors -g -std=c++17 -o ../../build/app_example2 + g++ app_example2.cpp -I../../include/ -I../../examples/ -Wfatal-errors -g -std=c++17 -o ../../build/app_example2 app_example3: app_example3.cpp - g++ app_example3.cpp -I../../include/ -I../../src/ -Wfatal-errors -g -std=c++17 -o ../../build/app_example3 + g++ app_example3.cpp -I../../include/ -I../../examples/ -Wfatal-errors -g -std=c++17 -o ../../build/app_example3 diff --git a/src/demo_cptr/BUILD b/examples/demo_cptr/BUILD similarity index 100% rename from src/demo_cptr/BUILD rename to examples/demo_cptr/BUILD diff --git a/src/demo_cptr/demo.cpp b/examples/demo_cptr/demo.cpp similarity index 100% rename from src/demo_cptr/demo.cpp rename to examples/demo_cptr/demo.cpp diff --git a/src/demo_cptr/demo0_cycles_test_graph.cpp b/examples/demo_cptr/demo0_cycles_test_graph.cpp similarity index 97% rename from src/demo_cptr/demo0_cycles_test_graph.cpp rename to examples/demo_cptr/demo0_cycles_test_graph.cpp index 8b1e80b..e0cb5de 100644 --- a/src/demo_cptr/demo0_cycles_test_graph.cpp +++ b/examples/demo_cptr/demo0_cycles_test_graph.cpp @@ -62,11 +62,12 @@ child that was never added"); children.erase(it); //--- Solution 2 (deferred_ptr) ----------------------------------------------- /*/ -static relation_pool<> pool; +static relation_pool<> pool; // NOLINT class MyGraph { public: class Node : public Counter { + private: vector> children; public: @@ -99,7 +100,8 @@ class MyGraph { void ShrinkToFit() { pool.getContext()->collect(); } static auto MakeNode() { - return relation_ptr::make(::pool.getContext()); + // return relation_ptr::make(::pool.getContext()); + return pool.make(); } private: diff --git a/src/demo_cptr/demo0_hsutter_gcpp_test_graph.cpp b/examples/demo_cptr/demo0_hsutter_gcpp_test_graph.cpp similarity index 100% rename from src/demo_cptr/demo0_hsutter_gcpp_test_graph.cpp rename to examples/demo_cptr/demo0_hsutter_gcpp_test_graph.cpp diff --git a/src/demo_cptr/demo_graph1.cpp b/examples/demo_cptr/demo_graph1.cpp similarity index 100% rename from src/demo_cptr/demo_graph1.cpp rename to examples/demo_cptr/demo_graph1.cpp diff --git a/src/demo_cptr/demo_list.cpp b/examples/demo_cptr/demo_list.cpp similarity index 100% rename from src/demo_cptr/demo_list.cpp rename to examples/demo_cptr/demo_list.cpp diff --git a/src/demo_cptr/demo_sizeof.cpp b/examples/demo_cptr/demo_sizeof.cpp similarity index 100% rename from src/demo_cptr/demo_sizeof.cpp rename to examples/demo_cptr/demo_sizeof.cpp diff --git a/src/demo_cptr/demo_tree.cpp b/examples/demo_cptr/demo_tree.cpp similarity index 100% rename from src/demo_cptr/demo_tree.cpp rename to examples/demo_cptr/demo_tree.cpp diff --git a/src/demo_cptr/makefile b/examples/demo_cptr/makefile similarity index 100% rename from src/demo_cptr/makefile rename to examples/demo_cptr/makefile diff --git a/src/examples/app_example1.cpp b/src/examples/app_example1.cpp deleted file mode 100644 index 3445a3a..0000000 --- a/src/examples/app_example1.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -#include - -using std::string, std::vector, std::map; - -using cycles::relation_pool; -using cycles::relation_ptr; - -class MyNode { - public: - double val; - std::vector> neighbors; - explicit MyNode(double val_) : val{val_} {} -}; - -class MyGraph { - public: - // Example: graph with entry, similar to a root in trees... but may be cyclic - relation_pool<> pool; // pool of data, similar to 'deferred_heap' - relation_ptr entry; // pointer to data, similar to 'deferred_ptr' -}; - -void printFrom(relation_ptr target, const relation_ptr& origin, - bool isFirst = false) { - if (!target || !origin) return; - if (isFirst || (target.get() != origin.get())) { - std::cout << target.get()->val << " "; - - for (const auto& node : target->neighbors) - printFrom(node.get_self_owned(), origin); - } -} - -int main() { - // begin example1 - { - MyGraph G; - - // create nodes -1, 1, 2 and 3 - G.entry = G.pool.make(-1.0); - relation_ptr ptr1 = G.pool.make(1.0); - relation_ptr ptr2 = G.pool.make(2.0); - relation_ptr ptr3 = G.pool.make(3.0); - - // manually generate a cycle: -1 -> 1 -> 2 -> 3 -> -1 -> ... - // entry node -1 has neighbor node 1 - G.entry->neighbors.push_back(ptr1.get_owned(G.entry)); - // node 1 has neighbor node 2 - ptr1->neighbors.push_back(ptr2.get_owned(ptr1)); - // node 2 has neighbor node 3 - ptr2->neighbors.push_back(ptr3.get_owned(ptr2)); - // finish cycle: node 3 has neighbor entry node -1 - ptr3->neighbors.push_back(G.entry.get_owned(ptr3)); - - // optional, destroy local variables (only keep 'G.entry') - ptr1.reset(); - ptr2.reset(); - ptr3.reset(); - - // nodes 1, 2, 3, -1, 1, 2, 3, -1, 1 ... still reachable from entry node -1 - assert(-1 == G.entry->val); - assert(2 == G.entry->neighbors[0]->neighbors[0]->val); - assert( - -1 == - G.entry->neighbors[0]->neighbors[0]->neighbors[0]->neighbors[0]->val); - // - std::cout << "printFrom(" << G.entry->val << ")" << std::endl; - printFrom(G.entry.get_self_owned(), G.entry, true); - std::cout << "finished" << std::endl; - } - // This will not leak! Even when a cycle exists from 'G.entry' - - return 0; -} diff --git a/src/examples/app_example2.cpp b/src/examples/app_example2.cpp deleted file mode 100644 index be15eae..0000000 --- a/src/examples/app_example2.cpp +++ /dev/null @@ -1,89 +0,0 @@ - -#include - -using std::string, std::vector, std::map; - -using cycles::relation_pool; -using cycles::relation_ptr; - -class MyNode { - public: - relation_ptr self; // self-ownership pattern - - double val; - std::vector> neighbors; - - explicit MyNode(double val_) : val{val_} {} - - void add_neighbor(const relation_ptr& node) { - self->neighbors.push_back(node.get_owned(self)); - } -}; - -class MyGraph { - public: - // Example: graph with entry, similar to a root in trees... but may be cyclic - relation_pool<> pool; // pool of data, similar to 'deferred_heap' - relation_ptr entry; // pointer to data, similar to 'deferred_ptr' - - // helper function to generate new pointers according to same 'pool' - auto make_self_node(double v) -> relation_ptr { - relation_ptr node = pool.make(v); - node->self = node.get_owned(node); // self-ownership pattern - return node; - } -}; - -void printFrom(relation_ptr target, const relation_ptr& origin, - bool isFirst = false) { - if (!target || !origin) return; - if (isFirst || (target.get() != origin.get())) { - std::cout << target.get()->val << " "; - - for (const auto& node : target->neighbors) - printFrom(node.get_self_owned(), origin); - } -} - -int main() { - // begin example2 - { - MyGraph G; - - // create nodes -1, 1, 2 and 3 - G.entry = G.make_self_node(-1.0); - relation_ptr ptr1 = G.make_self_node(1.0); - relation_ptr ptr2 = G.make_self_node(2.0); - relation_ptr ptr3 = G.make_self_node(3.0); - - // manually generate a cycle: -1 -> 1 -> 2 -> 3 -> -1 -> ... - // entry node -1 has neighbor node 1 - G.entry->add_neighbor(ptr1); - // node 1 has neighbor node 2 - ptr1->add_neighbor(ptr2); - // node 2 has neighbor node 3 - ptr2->add_neighbor(ptr3); - // finish cycle: node 3 has neighbor entry node -1 - ptr3->add_neighbor(G.entry); - - // optional, destroy local variables (only keep 'G.entry') - ptr1.reset(); - ptr2.reset(); - ptr3.reset(); - - // nodes 1, 2, 3, -1, 1, 2, 3, -1, 1 ... still reachable from entry node - // -1 - assert(-1 == G.entry->val); - assert(2 == G.entry->neighbors[0]->neighbors[0]->val); - assert( - -1 == - G.entry->neighbors[0]->neighbors[0]->neighbors[0]->neighbors[0]->val); - // - std::cout << "printFrom(" << G.entry->val << ")" << std::endl; - printFrom(G.entry.get_self_owned(), G.entry, true); - std::cout << "finished" << std::endl; - } - // This will not leak! Even when a cycle exists from 'G.entry' - - return 0; -} diff --git a/src/examples/app_example3.cpp b/src/examples/app_example3.cpp deleted file mode 100644 index 8e7a6a8..0000000 --- a/src/examples/app_example3.cpp +++ /dev/null @@ -1,101 +0,0 @@ - -#include - -using std::string, std::vector, std::map; - -using cycles::relation_pool; -using cycles::relation_ptr; - -class MyNode { - public: - double val; - - explicit MyNode(double _val) : val{_val} {} - - private: - relation_ptr self; // self-ownership pattern - relation_ptr _next; - relation_ptr _prev; - - public: - void set_self(const relation_ptr& node) { - if (!self && (node.get() == this)) self = node.get_owned(node); - } - - relation_ptr next() const { return _next.get_owned(_next); } - relation_ptr prev() const { return _prev.get_owned(_prev); } - - void set_next(const relation_ptr& node) { - self->_next = node.get_owned(self); - } - - void set_prev(const relation_ptr& node) { - self->_prev = node.get_owned(self); - } - - // add node as self->next, and node->prev as self - void add_next(const relation_ptr& node) { - assert(node); - assert(self); - self->_next = node.get_owned(self); - node->_prev = self.get_owned(node); - } -}; - -class MyList { - private: - // no pool needed - relation_ptr _entry; - - public: - relation_ptr entry() { return _entry.get_owned(_entry); } - - void set_entry(double val) { - sptr ctx{ - new cycles::detail::DynowForestV1{}}; - _entry = relation_ptr{new MyNode{val}, ctx}; - _entry->set_self(_entry); - } - - // helper function to generate new pointers according to same 'pool' - auto make_self_node(double val) -> relation_ptr { - assert(_entry); - relation_ptr node{new MyNode{val}, _entry.get_ctx()}; - node->set_self(node); // self-ownership pattern - return node; - } -}; - -void printFrom(relation_ptr current, const relation_ptr& origin, - bool isFirst = false) { - if (!current || !origin) return; - if (isFirst || (current.get() != origin.get())) { - std::cout << current.get()->val << " "; - if (current->next()) printFrom(current->next(), origin); - } -} - -int main() { - // begin example3 - { - MyList L; - - // create nodes -1, 1, 2 and 3 - L.set_entry(-1.0); - assert(L.entry()); - L.entry()->add_next(L.make_self_node(1)); - L.entry()->next()->add_next(L.make_self_node(2)); - L.entry()->next()->next()->add_next(L.make_self_node(3)); - // manually finish cycle - L.entry()->next()->next()->next()->set_next(L.entry()); - L.entry()->set_prev(L.entry()->next()->next()->next()); - - // - std::cout << "printFrom(" << L.entry()->val << ")" << std::endl; - printFrom(L.entry(), L.entry(), true); - std::cout << "finished" << std::endl; - } - // This will not leak! Even when a cycle exists from 'L.entry' - - return 0; -} diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index 1bce6b8..0c9cfcc 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -8,7 +8,7 @@ cc_test( srcs = glob([ "MyGraph.Test.cpp", ]), - defines = ["CATCH_CONFIG_MAIN", "CYCLES_TOSTRING", "CYCLES_TEST"], + defines = ["CATCH_CONFIG_MAIN", "CYCLES_TOSTRING", "CYCLES_TEST", "HEADER_ONLY"], deps = ["//include/cycles:cycles_hpp", "//include/demo_cptr:demo_cptr_hpp", ":catch2_thirdparty"] @@ -19,7 +19,7 @@ cc_test( srcs = glob([ "MyList.Test.cpp", ]), - defines = ["CATCH_CONFIG_MAIN", "CYCLES_TOSTRING", "CYCLES_TEST"], + defines = ["CATCH_CONFIG_MAIN", "CYCLES_TOSTRING", "CYCLES_TEST", "HEADER_ONLY"], deps = ["//include/cycles:cycles_hpp", "//include/demo_cptr:demo_cptr_hpp", ":catch2_thirdparty"] @@ -30,7 +30,7 @@ cc_test( srcs = glob([ "TNode.Test.cpp", ]), - defines = ["CATCH_CONFIG_MAIN", "CYCLES_TOSTRING"], + defines = ["CATCH_CONFIG_MAIN", "CYCLES_TOSTRING", "CYCLES_TEST", "HEADER_ONLY"], deps = ["//include/cycles:cycles_hpp", ":catch2_thirdparty"] ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..935cbcd --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,48 @@ + +#========== +# TESTS +#---------- +# add_subdirectory(tests/thirdparty/catch2/) +FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.1) +FetchContent_MakeAvailable(Catch2) +# +list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) +include(CTest) +include(Catch) +# +add_executable(my_graph_test MyGraph.Test.cpp) +target_link_libraries(my_graph_test PRIVATE cycles Catch2::Catch2WithMain) +# +add_executable(my_list_test MyList.Test.cpp) +target_link_libraries(my_list_test PRIVATE cycles Catch2::Catch2WithMain) +# +add_compile_definitions(CYCLES_TEST) # just for testing ? +catch_discover_tests(my_graph_test my_list_test) + + +# MANUAL: +# target_link_libraries(my_test PUBLIC Catch2) +# enable_testing() +# add_test(NAME MeusTestes COMMAND my_test) + + +# ======== +# bench + +add_executable(long_bench_graph bench/long_bench_graph.cpp) +target_link_libraries(long_bench_graph PRIVATE cycles) +# +add_executable(quick_bench_graph bench/quick_bench_graph.cpp) +target_link_libraries(quick_bench_graph PRIVATE cycles) +# +add_executable(quick_bench_list_tree bench/quick_bench_list_tree.cpp) +target_link_libraries(quick_bench_list_tree PRIVATE cycles) +# +# hsutter gcpp dependency +# +include_directories(thirdparty/) +# gsl dependency +include_directories(thirdparty/hsutter-gcpp/submodules/gsl/include) +# +add_executable(quick_bench_sptr bench/quick_bench_sptr.cpp) +target_link_libraries(quick_bench_sptr PRIVATE cycles) diff --git a/tests/MyGraph.Test.cpp b/tests/MyGraph.Test.cpp index 53e00be..3aca190 100644 --- a/tests/MyGraph.Test.cpp +++ b/tests/MyGraph.Test.cpp @@ -2,7 +2,11 @@ // #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() #include // +#ifdef HEADER_ONLY #include +#else +#include +#endif #include using namespace std; // NOLINT diff --git a/tests/MyList.Test.cpp b/tests/MyList.Test.cpp index 931cde6..0d91e08 100644 --- a/tests/MyList.Test.cpp +++ b/tests/MyList.Test.cpp @@ -2,7 +2,11 @@ // #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() #include // +#ifdef HEADER_ONLY #include +#else +#include +#endif // // #include #include diff --git a/tests/TNode.Test.cpp b/tests/TNode.Test.cpp index ecf8bd9..1b28273 100644 --- a/tests/TNode.Test.cpp +++ b/tests/TNode.Test.cpp @@ -2,7 +2,11 @@ // #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() #include // +#ifdef HEADER_ONLY #include +#else +#include +#endif #include #include diff --git a/tests/bench/quick_bench_sptr.cpp b/tests/bench/quick_bench_sptr.cpp index d2168f3..81d96bf 100644 --- a/tests/bench/quick_bench_sptr.cpp +++ b/tests/bench/quick_bench_sptr.cpp @@ -13,28 +13,29 @@ int main() { auto c = high_resolution_clock::now(); { // auto data = make_tracked[]>(10000000); - sptr ctx{new DynowForestV1{}}; + // sptr ctx{new DynowForestV1{}}; + relation_pool<> pool; std::vector> data(10000000); for (int i = 0; i < 10000000; ++i) { // if (i % 1000) std::cout << "i=" << i << std::endl; switch (i % 6) { case 0: - data[i] = relation_ptr::make(ctx); + data[i] = pool.make(); break; case 1: - data[i] = relation_ptr::make(ctx); + data[i] = pool.make(); break; case 2: - data[i] = relation_ptr::make(ctx); + data[i] = pool.make(); break; case 3: - data[i] = relation_ptr::make(ctx); + data[i] = pool.make(); break; case 4: - data[i] = relation_ptr::make(ctx); + data[i] = pool.make(); break; case 5: - data[i] = relation_ptr::make(ctx); + data[i] = pool.make(); break; } } diff --git a/tests/makefile b/tests/makefile index 65a542a..7ac0fda 100644 --- a/tests/makefile +++ b/tests/makefile @@ -1,11 +1,11 @@ all: test_catch2 bazel_test test_quick_bench # test_demo_graph2 test_demo_graph2: demo_graph2.cpp - g++ demo_graph2.cpp -I../include/ -I../src -g -std=c++17 -DCYCLES_TEST -o ../build/test_demo_graph2 + g++ demo_graph2.cpp -I../include/ -I../examples -g -std=c++17 -DCYCLES_TEST -o ../build/test_demo_graph2 valgrind ../build/test_demo_graph2 test_catch2: - g++ TNode.Test.cpp MyGraph.Test.cpp MyList.Test.cpp -g --std=c++17 -DCYCLES_TEST -I../include/ -I../src -Ithirdparty/ thirdparty/catch2/catch_amalgamated.cpp -DCYCLES_TOSTRING -o ../build/test_catch2 + g++ TNode.Test.cpp MyGraph.Test.cpp MyList.Test.cpp -g --std=c++17 -DCYCLES_TEST -DHEADER_ONLY -I../include/ -I../examples -Ithirdparty/ thirdparty/catch2/catch_amalgamated.cpp -DCYCLES_TOSTRING -o ../build/test_catch2 valgrind --leak-check=full ../build/test_catch2 test_quick_bench: bench_list_tree_build @@ -19,12 +19,12 @@ test_quick_bench: bench_list_tree_build bench: bench_sptr bench_list_tree bench_graph bench_sptr: - g++ bench/quick_bench_sptr.cpp -Wfatal-errors -std=c++17 -g -Ofast -I../include/ -I../src -o ../build/bench_sptr + g++ bench/quick_bench_sptr.cpp -Wfatal-errors -std=c++17 -g -Ofast -I../include/ -I../examples -o ../build/bench_sptr ../build/bench_sptr bench_list_tree_build: - g++ bench/quick_bench_list_tree.cpp -Wfatal-errors -DBENCH_LONG_DEFERRED -std=c++17 -g -Ofast -I../include/ -I../src -o ../build/bench_list_tree - g++ bench/quick_bench_list_tree.cpp -Wfatal-errors -std=c++17 -g -Ofast -I../include/ -I../src -o ../build/bench_list_tree_nodeferred + g++ bench/quick_bench_list_tree.cpp -Wfatal-errors -DBENCH_LONG_DEFERRED -std=c++17 -g -Ofast -I../include/ -I../examples -o ../build/bench_list_tree + g++ bench/quick_bench_list_tree.cpp -Wfatal-errors -std=c++17 -g -Ofast -I../include/ -I../examples -o ../build/bench_list_tree_nodeferred bench_list_tree: bench_list_tree_build # @@ -48,10 +48,10 @@ bench_list_tree: bench_list_tree_build bench_graph: - # g++ bench/quick_bench_graph.cpp -std=c++17 -g -Ofast -I../include/ -Ithirdparty -I../src -o ../build/quick_bench_graph + # g++ bench/quick_bench_graph.cpp -std=c++17 -g -Ofast -I../include/ -Ithirdparty -I../examples -o ../build/quick_bench_graph # valgrind --leak-check=full ../build/quick_bench_graph # - g++ bench/long_bench_graph.cpp -std=c++17 -g -Ofast -I../include/ -Ithirdparty -Ithirdparty/hsutter-gcpp/submodules/gsl/include -I../src -o ../build/long_bench_graph + g++ bench/long_bench_graph.cpp -std=c++17 -g -Ofast -I../include/ -Ithirdparty -Ithirdparty/hsutter-gcpp/submodules/gsl/include -I../examples -o ../build/long_bench_graph ../build/long_bench_graph valgrind --leak-check=full ../build/long_bench_graph