From 0588de76bb06e953e7e08d70208148332da4e435 Mon Sep 17 00:00:00 2001 From: Mislav Bradac Date: Thu, 6 Jul 2017 17:47:28 +0200 Subject: [PATCH] Move unused datastructures to poc Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D526 --- poc/CMakeLists.txt | 4 + .../allocator_benchmark.cpp | 4 +- .../allocator.cpp => poc/allocator_test.cpp | 2 +- {tests/unit => poc}/basic_bloom_filter.cpp | 2 +- .../basic_bloom_filter_benchmark.cpp | 2 +- .../block_allocator_test.cpp | 4 +- .../bloom => poc}/bloom_filter.hpp | 1 + .../bloom_map_concurrent.cpp | 4 +- .../queue => poc}/bounded_spsc_queue.hpp | 0 .../concurrent_bloom_map.hpp | 0 {src/memory => poc}/hp.hpp | 3 +- {src/data_structures => poc}/kdtree/build.hpp | 0 .../data_structures => poc}/kdtree/kdnode.hpp | 0 .../data_structures => poc}/kdtree/kdtree.hpp | 0 {src/data_structures => poc}/kdtree/math.hpp | 0 {src/data_structures => poc}/kdtree/nns.hpp | 0 {src/data_structures => poc}/kdtree/point.hpp | 0 {src/utils => poc}/memory/allocator.hpp | 0 .../memory/atomic_shared_ptr.hpp | 1 + {src/utils => poc}/memory/block_allocator.hpp | 0 {src/utils => poc}/memory/maker.hpp | 0 {src/utils => poc}/memory/stack_allocator.hpp | 2 +- .../queue => poc}/mpsc_queue.hpp | 0 {src/utils => poc}/option_ptr.hpp | 0 poc/ptr_int.hpp | 51 +++ poc/ptr_int_test.cpp | 26 ++ .../map/rh_common.hpp => poc/rh_hashmap.hpp | 175 +++++++- .../rh_hashmap.cpp => poc/rh_hashmap_test.cpp | 2 +- .../stack_allocator_test.cpp | 2 +- .../union_find => poc}/union_find.hpp | 0 .../union_find.cpp => poc/union_find_test.cpp | 18 +- src/data_structures/map/rh_hashmap.hpp | 177 --------- src/data_structures/static_array.hpp | 58 --- src/dbms/cleaner.cpp | 69 ---- src/dbms/cleaner.hpp | 26 -- src/dbms/dbms.hpp | 9 - src/io/network/stream_reader.hpp | 2 +- src/memory/deferred_recycler.hpp | 25 -- src/memory/freelist.hpp | 22 - src/memory/lazy_gc.hpp | 24 -- src/memory/memory.hpp | 41 -- src/memory/recycler.hpp | 41 -- src/mvcc/version_list.hpp | 1 - src/threading/global_pool.hpp | 32 -- src/traversal/enums.hpp | 26 +- src/traversal/path.hpp | 49 +-- src/traversal/templates.hpp | 375 +++++++++--------- src/traversal/traversal.hpp | 26 +- .../memory_literals.hpp} | 0 src/utils/{timer => }/timer.hpp | 0 tests/CMakeLists.txt | 2 - tests/concurrent/{common.h => common.hpp} | 11 +- tests/concurrent/conncurent_list.cpp | 2 +- tests/concurrent/dynamic_bitset.cpp | 2 +- tests/concurrent/dynamic_bitset_clear_n.cpp | 2 +- tests/concurrent/dynamic_bitset_set.cpp | 2 +- tests/concurrent/dynamic_bitset_set_n.cpp | 2 +- tests/concurrent/measure_time.cpp | 2 +- tests/concurrent/sl_insert.cpp | 2 +- tests/concurrent/sl_insert_competetive.cpp | 2 +- tests/concurrent/sl_map.cpp | 12 +- tests/concurrent/sl_memory.cpp | 2 +- tests/concurrent/sl_memory_leak.cpp | 12 +- tests/concurrent/sl_remove_competetive.cpp | 2 +- tests/concurrent/sl_remove_disjoint.cpp | 2 +- tests/concurrent/sl_remove_joint.cpp | 2 +- tests/concurrent/sl_set.cpp | 2 +- tests/concurrent/sl_simulation.cpp | 2 +- 68 files changed, 542 insertions(+), 829 deletions(-) rename tests/benchmark/allocator.cpp => poc/allocator_benchmark.cpp (95%) rename tests/unit/allocator.cpp => poc/allocator_test.cpp (97%) rename {tests/unit => poc}/basic_bloom_filter.cpp (94%) rename tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp => poc/basic_bloom_filter_benchmark.cpp (96%) rename tests/unit/block_allocator.cpp => poc/block_allocator_test.cpp (87%) rename {src/data_structures/bloom => poc}/bloom_filter.hpp (98%) rename {tests/benchmark/data_structures/concurrent => poc}/bloom_map_concurrent.cpp (97%) rename {src/data_structures/queue => poc}/bounded_spsc_queue.hpp (100%) rename {src/data_structures/concurrent => poc}/concurrent_bloom_map.hpp (100%) rename {src/memory => poc}/hp.hpp (97%) rename {src/data_structures => poc}/kdtree/build.hpp (100%) rename {src/data_structures => poc}/kdtree/kdnode.hpp (100%) rename {src/data_structures => poc}/kdtree/kdtree.hpp (100%) rename {src/data_structures => poc}/kdtree/math.hpp (100%) rename {src/data_structures => poc}/kdtree/nns.hpp (100%) rename {src/data_structures => poc}/kdtree/point.hpp (100%) rename {src/utils => poc}/memory/allocator.hpp (100%) rename {src/utils => poc}/memory/atomic_shared_ptr.hpp (94%) rename {src/utils => poc}/memory/block_allocator.hpp (100%) rename {src/utils => poc}/memory/maker.hpp (100%) rename {src/utils => poc}/memory/stack_allocator.hpp (98%) rename {src/data_structures/queue => poc}/mpsc_queue.hpp (100%) rename {src/utils => poc}/option_ptr.hpp (100%) create mode 100644 poc/ptr_int.hpp create mode 100644 poc/ptr_int_test.cpp rename src/data_structures/map/rh_common.hpp => poc/rh_hashmap.hpp (58%) rename tests/unit/rh_hashmap.cpp => poc/rh_hashmap_test.cpp (98%) rename tests/unit/stack_allocator.cpp => poc/stack_allocator_test.cpp (92%) rename {src/data_structures/union_find => poc}/union_find.hpp (100%) rename tests/unit/union_find.cpp => poc/union_find_test.cpp (80%) delete mode 100644 src/data_structures/map/rh_hashmap.hpp delete mode 100644 src/data_structures/static_array.hpp delete mode 100644 src/dbms/cleaner.cpp delete mode 100644 src/dbms/cleaner.hpp delete mode 100644 src/memory/deferred_recycler.hpp delete mode 100644 src/memory/freelist.hpp delete mode 100644 src/memory/lazy_gc.hpp delete mode 100644 src/memory/memory.hpp delete mode 100644 src/memory/recycler.hpp delete mode 100644 src/threading/global_pool.hpp rename src/{memory/literals.hpp => utils/memory_literals.hpp} (100%) rename src/utils/{timer => }/timer.hpp (100%) rename tests/concurrent/{common.h => common.hpp} (95%) diff --git a/poc/CMakeLists.txt b/poc/CMakeLists.txt index 92392f97b..2be78a07e 100644 --- a/poc/CMakeLists.txt +++ b/poc/CMakeLists.txt @@ -26,5 +26,9 @@ foreach(poc_cpp ${poc_cpps}) # link libraries target_link_libraries(${target_name} memgraph_lib) + # gtest + target_link_libraries(${target_name} gtest gtest_main gmock) + # google-benchmark + target_link_libraries(${target_name} benchmark ${CMAKE_THREAD_LIBS_INIT}) endforeach() diff --git a/tests/benchmark/allocator.cpp b/poc/allocator_benchmark.cpp similarity index 95% rename from tests/benchmark/allocator.cpp rename to poc/allocator_benchmark.cpp index fb6ee3706..b84de4491 100644 --- a/tests/benchmark/allocator.cpp +++ b/poc/allocator_benchmark.cpp @@ -3,10 +3,10 @@ #include #include +#include "memory/allocator.hpp" +#include "memory/maker.hpp" #include "utils/assert.hpp" #include "utils/measure_time.hpp" -#include "utils/memory/allocator.hpp" -#include "utils/memory/maker.hpp" struct TestStructure { TestStructure(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {} diff --git a/tests/unit/allocator.cpp b/poc/allocator_test.cpp similarity index 97% rename from tests/unit/allocator.cpp rename to poc/allocator_test.cpp index 970c068dc..e7f225d15 100644 --- a/tests/unit/allocator.cpp +++ b/poc/allocator_test.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "utils/memory/allocator.hpp" +#include "memory/allocator.hpp" TEST(AllocatorTest, ABlockOfIntegersCanBeAllocated) { constexpr int N = 100; diff --git a/tests/unit/basic_bloom_filter.cpp b/poc/basic_bloom_filter.cpp similarity index 94% rename from tests/unit/basic_bloom_filter.cpp rename to poc/basic_bloom_filter.cpp index 26acbb3e0..a8f91953a 100644 --- a/tests/unit/basic_bloom_filter.cpp +++ b/poc/basic_bloom_filter.cpp @@ -2,7 +2,7 @@ #include -#include "data_structures/bloom/bloom_filter.hpp" +#include "bloom_filter.hpp" #include "utils/hashing/fnv64.hpp" using StringHashFunction = std::function; diff --git a/tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp b/poc/basic_bloom_filter_benchmark.cpp similarity index 96% rename from tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp rename to poc/basic_bloom_filter_benchmark.cpp index 6e237f7be..15fc22d8e 100644 --- a/tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp +++ b/poc/basic_bloom_filter_benchmark.cpp @@ -4,7 +4,7 @@ #include #include -#include "data_structures/bloom/bloom_filter.hpp" +#include "bloom_filter.hpp" #include "utils/hashing/fnv64.hpp" #include "utils/random/random_generator.hpp" diff --git a/tests/unit/block_allocator.cpp b/poc/block_allocator_test.cpp similarity index 87% rename from tests/unit/block_allocator.cpp rename to poc/block_allocator_test.cpp index aa7b54ac9..6d65d766a 100644 --- a/tests/unit/block_allocator.cpp +++ b/poc/block_allocator_test.cpp @@ -1,6 +1,6 @@ -#include "gtest/gtest.h" +#include -#include "utils/memory/block_allocator.hpp" +#include "memory/block_allocator.hpp" TEST(BlockAllocatorTest, UnusedVsReleaseSize) { BlockAllocator<64> block_allocator(10); diff --git a/src/data_structures/bloom/bloom_filter.hpp b/poc/bloom_filter.hpp similarity index 98% rename from src/data_structures/bloom/bloom_filter.hpp rename to poc/bloom_filter.hpp index a3c8eb760..ad660bf44 100644 --- a/src/data_structures/bloom/bloom_filter.hpp +++ b/poc/bloom_filter.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp b/poc/bloom_map_concurrent.cpp similarity index 97% rename from tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp rename to poc/bloom_map_concurrent.cpp index d00f4fc1b..2c17925df 100644 --- a/tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp +++ b/poc/bloom_map_concurrent.cpp @@ -5,8 +5,8 @@ #include #include -#include "data_structures/bloom/bloom_filter.hpp" -#include "data_structures/concurrent/concurrent_bloom_map.hpp" +#include "bloom_filter.hpp" +#include "concurrent_bloom_map.hpp" #include "utils/hashing/fnv64.hpp" #include "utils/random/random_generator.hpp" diff --git a/src/data_structures/queue/bounded_spsc_queue.hpp b/poc/bounded_spsc_queue.hpp similarity index 100% rename from src/data_structures/queue/bounded_spsc_queue.hpp rename to poc/bounded_spsc_queue.hpp diff --git a/src/data_structures/concurrent/concurrent_bloom_map.hpp b/poc/concurrent_bloom_map.hpp similarity index 100% rename from src/data_structures/concurrent/concurrent_bloom_map.hpp rename to poc/concurrent_bloom_map.hpp diff --git a/src/memory/hp.hpp b/poc/hp.hpp similarity index 97% rename from src/memory/hp.hpp rename to poc/hp.hpp index b3227d57b..57cd5c0cf 100644 --- a/src/memory/hp.hpp +++ b/poc/hp.hpp @@ -50,7 +50,8 @@ class HP { hp.clear(*this); } - reference& operator=(reference&& other) { return *this; } + // TODO: ??? + reference& operator=(reference&&) { return *this; } private: reference(int64_t idx) : idx(idx) {} diff --git a/src/data_structures/kdtree/build.hpp b/poc/kdtree/build.hpp similarity index 100% rename from src/data_structures/kdtree/build.hpp rename to poc/kdtree/build.hpp diff --git a/src/data_structures/kdtree/kdnode.hpp b/poc/kdtree/kdnode.hpp similarity index 100% rename from src/data_structures/kdtree/kdnode.hpp rename to poc/kdtree/kdnode.hpp diff --git a/src/data_structures/kdtree/kdtree.hpp b/poc/kdtree/kdtree.hpp similarity index 100% rename from src/data_structures/kdtree/kdtree.hpp rename to poc/kdtree/kdtree.hpp diff --git a/src/data_structures/kdtree/math.hpp b/poc/kdtree/math.hpp similarity index 100% rename from src/data_structures/kdtree/math.hpp rename to poc/kdtree/math.hpp diff --git a/src/data_structures/kdtree/nns.hpp b/poc/kdtree/nns.hpp similarity index 100% rename from src/data_structures/kdtree/nns.hpp rename to poc/kdtree/nns.hpp diff --git a/src/data_structures/kdtree/point.hpp b/poc/kdtree/point.hpp similarity index 100% rename from src/data_structures/kdtree/point.hpp rename to poc/kdtree/point.hpp diff --git a/src/utils/memory/allocator.hpp b/poc/memory/allocator.hpp similarity index 100% rename from src/utils/memory/allocator.hpp rename to poc/memory/allocator.hpp diff --git a/src/utils/memory/atomic_shared_ptr.hpp b/poc/memory/atomic_shared_ptr.hpp similarity index 94% rename from src/utils/memory/atomic_shared_ptr.hpp rename to poc/memory/atomic_shared_ptr.hpp index 6197b2e9b..eb0e20183 100644 --- a/src/utils/memory/atomic_shared_ptr.hpp +++ b/poc/memory/atomic_shared_ptr.hpp @@ -3,6 +3,7 @@ #include #include +// I heard this is patented. template class atomic_shared_ptr final { public: diff --git a/src/utils/memory/block_allocator.hpp b/poc/memory/block_allocator.hpp similarity index 100% rename from src/utils/memory/block_allocator.hpp rename to poc/memory/block_allocator.hpp diff --git a/src/utils/memory/maker.hpp b/poc/memory/maker.hpp similarity index 100% rename from src/utils/memory/maker.hpp rename to poc/memory/maker.hpp diff --git a/src/utils/memory/stack_allocator.hpp b/poc/memory/stack_allocator.hpp similarity index 98% rename from src/utils/memory/stack_allocator.hpp rename to poc/memory/stack_allocator.hpp index edd83f6d7..3d1b530a9 100644 --- a/src/utils/memory/stack_allocator.hpp +++ b/poc/memory/stack_allocator.hpp @@ -2,9 +2,9 @@ #include +#include "memory/block_allocator.hpp" #include "utils/exceptions.hpp" #include "utils/likely.hpp" -#include "utils/memory/block_allocator.hpp" // http://en.cppreference.com/w/cpp/language/new diff --git a/src/data_structures/queue/mpsc_queue.hpp b/poc/mpsc_queue.hpp similarity index 100% rename from src/data_structures/queue/mpsc_queue.hpp rename to poc/mpsc_queue.hpp diff --git a/src/utils/option_ptr.hpp b/poc/option_ptr.hpp similarity index 100% rename from src/utils/option_ptr.hpp rename to poc/option_ptr.hpp diff --git a/poc/ptr_int.hpp b/poc/ptr_int.hpp new file mode 100644 index 000000000..27c461f2f --- /dev/null +++ b/poc/ptr_int.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include + +constexpr std::size_t log2(std::size_t n) { + return ((n < 2) ? 0 : 1 + log2(n >> 1)); +} + +template +struct PointerPackTraits { + // here is a place to embed something like platform specific things + // TODO: cover more cases + constexpr static int free_bits = log2(alignof(PtrT)); + + static auto get_ptr(uintptr_t value) { return (PtrT)(value); } +}; + +template > +class PtrInt { + private: + constexpr static int int_shift = PtrTraits::free_bits - IntBits; + constexpr static uintptr_t ptr_mask = + ~(uintptr_t)(((intptr_t)1 << PtrTraits::free_bits) - 1); + constexpr static uintptr_t int_mask = + (uintptr_t)(((intptr_t)1 << IntBits) - 1); + + uintptr_t value{0}; + + public: + PtrInt(PtrT pointer, IntT integer) { + set_ptr(pointer); + set_int(integer); + } + + auto set_ptr(PtrT pointer) { + auto integer = static_cast(get_int()); + auto ptr = reinterpret_cast(pointer); + value = (ptr_mask & ptr) | (integer << int_shift); + } + + auto set_int(IntT integer) { + auto ptr = reinterpret_cast(get_ptr()); + auto int_shifted = static_cast(integer << int_shift); + value = (int_mask & int_shifted) | ptr; + } + + auto get_ptr() const { return PtrTraits::get_ptr(value & ptr_mask); } + + auto get_int() const { return (IntT)((value >> int_shift) & int_mask); } +}; diff --git a/poc/ptr_int_test.cpp b/poc/ptr_int_test.cpp new file mode 100644 index 000000000..e8a2c98c0 --- /dev/null +++ b/poc/ptr_int_test.cpp @@ -0,0 +1,26 @@ +#include + +#include "ptr_int.hpp" + +TEST(PtrInt, SizeOf) { + ASSERT_EQ(sizeof(PtrInt), sizeof(uintptr_t)); +} + +TEST(PtrInt, ConstructionAndRead) { + auto ptr1 = std::make_unique(2); + PtrInt pack1(ptr1.get(), 1); + + ASSERT_EQ(pack1.get_int(), 1); + ASSERT_EQ(pack1.get_ptr(), ptr1.get()); + + auto ptr2 = std::make_unique(2); + PtrInt pack2(ptr2.get(), 4); + + ASSERT_EQ(pack2.get_int(), 4); + ASSERT_EQ(pack2.get_ptr(), ptr2.get()); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/data_structures/map/rh_common.hpp b/poc/rh_hashmap.hpp similarity index 58% rename from src/data_structures/map/rh_common.hpp rename to poc/rh_hashmap.hpp index 67b7ea924..0ae80a94e 100644 --- a/src/data_structures/map/rh_common.hpp +++ b/poc/rh_hashmap.hpp @@ -1,9 +1,11 @@ #pragma once + #include #include + +#include "option_ptr.hpp" #include "utils/assert.hpp" #include "utils/crtp.hpp" -#include "utils/option_ptr.hpp" // RobinHood base. // Entries are POINTERS alligned to 8B. @@ -286,3 +288,174 @@ class RhBase { friend class IteratorBase; friend class IteratorBase; }; + +/** + * HashMap with RobinHood collision resolution policy. + * Single threaded. + * Entries are saved as pointers alligned to 8B. + * Entries must know thers key. + * D must have method const K & get_key() + * K must be comparable with ==. + * HashMap behaves as if it isn't owner of entries. + * BE CAREFUL - this structure assumes that the pointer to Data is 8-alligned! +*/ +template +class RhHashMap : public RhBase { + typedef RhBase base; + using base::array; + using base::index; + using base::capacity; + using base::count; + using typename base::Combined; + + void increase_size() { + size_t old_size = capacity; + auto a = array; + if (base::increase_size()) { + for (int i = 0; i < old_size; i++) { + if (a[i].valid()) { + insert(a[i].ptr()); + } + } + } + + free(a); + } + + public: + using base::RhBase; + + bool contains(const K &key) { return find(key).is_present(); } + + OptionPtr find(const K key) { + size_t mask = this->mask(); + size_t now = index(key, mask); + size_t off = 0; + size_t border = 8 <= capacity ? 8 : capacity; + + while (off < border) { + Combined other = array[now]; + if (other.valid()) { + auto other_off = other.off(); + if (other_off == off && key == other.ptr()->get_key()) { + // Found data. + return OptionPtr(other.ptr()); + + } else if (other_off < off) { // Other is rich + break; + } // Else other has equal or greater offset, so he is poor. + } else { + // Empty slot means that there is no searched data. + break; + } + + off++; + now = (now + 1) & mask; + } + return OptionPtr(); + } + + // Inserts element. Returns true if element wasn't in the map. + bool insert(D *data) { + permanent_assert(!(((uint64_t) static_cast(data) & 7)), + "Data is not 8-alligned."); + if (count < capacity) { + size_t mask = this->mask(); + auto key = std::ref(data->get_key()); + size_t now = index(key, mask); + size_t off = 0; + size_t border = 8 <= capacity ? 8 : capacity; + + while (off < border) { + Combined other = array[now]; + if (other.valid()) { + auto other_off = other.off(); + if (other_off == off && key == other.ptr()->get_key()) { + // Element already exists. + return false; + + } else if (other_off < off) { // Other is rich + // Set data. + array[now] = Combined(data, off); + + // Move other data to the higher indexes, + while (other.increment_off()) { + now = (now + 1) & mask; + auto tmp = array[now]; + array[now] = other; + other = tmp; + if (!other.valid()) { + count++; + return true; + } + } + data = other.ptr(); + break; // Cant insert removed element because it would + // be to far from his real place. + } // Else other has equal or greater offset, so he is poor. + } else { + // Data can be placed in this empty slot. + array[now] = Combined(data, off); + count++; + return true; + } + + off++; + now = (now + 1) & mask; + } + } + + // There isn't enough space for element pointed by data so whe must + // increase array. + increase_size(); + return insert(data); + } + + // Removes element. Returns removed element if it existed. + OptionPtr remove(const K &key) { + size_t mask = this->mask(); + size_t now = index(key, mask); + size_t off = 0; + size_t border = 8 <= capacity ? 8 : capacity; + + while (off < border) { + Combined other = array[now]; + if (other.valid()) { + auto other_off = other.off(); + auto other_ptr = other.ptr(); + if (other_off == off && key == other_ptr->get_key()) { // Found it + + auto before = now; + // Whe must move other elements one slot lower. + do { + // This is alright even for off=0 on found element + // because it wont be seen. + other.decrement_off_unsafe(); + + array[before] = other; + before = now; + now = (now + 1) & mask; + other = array[now]; + } while (other.valid() && + other.off() > 0); // Exit if whe encounter empty + // slot or data which is exactly + // in slot which it want's to be. + + array[before] = Combined(); + count--; + return OptionPtr(other_ptr); + + } else if (other_off < off) { // Other is rich + break; + } // Else other has equal or greater offset, so he is poor. + } else { + // If the element to be removed existed in map it would be here. + break; + } + + off++; + now = (now + 1) & mask; + } + return OptionPtr(); + } +}; diff --git a/tests/unit/rh_hashmap.cpp b/poc/rh_hashmap_test.cpp similarity index 98% rename from tests/unit/rh_hashmap.cpp rename to poc/rh_hashmap_test.cpp index 0ea1b3042..56dbbbffc 100644 --- a/tests/unit/rh_hashmap.cpp +++ b/poc/rh_hashmap_test.cpp @@ -1,7 +1,7 @@ #include "gtest/gtest.h" #include -#include "data_structures/map/rh_hashmap.hpp" +#include "rh_hashmap.hpp" class Data { private: diff --git a/tests/unit/stack_allocator.cpp b/poc/stack_allocator_test.cpp similarity index 92% rename from tests/unit/stack_allocator.cpp rename to poc/stack_allocator_test.cpp index a7496d004..b3b229ba5 100644 --- a/tests/unit/stack_allocator.cpp +++ b/poc/stack_allocator_test.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "utils/memory/stack_allocator.hpp" +#include "memory/stack_allocator.hpp" struct Object { int a; diff --git a/src/data_structures/union_find/union_find.hpp b/poc/union_find.hpp similarity index 100% rename from src/data_structures/union_find/union_find.hpp rename to poc/union_find.hpp diff --git a/tests/unit/union_find.cpp b/poc/union_find_test.cpp similarity index 80% rename from tests/unit/union_find.cpp rename to poc/union_find_test.cpp index aefbe01a7..42f021037 100644 --- a/tests/unit/union_find.cpp +++ b/poc/union_find_test.cpp @@ -3,9 +3,9 @@ #include "gtest/gtest.h" -#include "data_structures/union_find/union_find.hpp" +#include "union_find.hpp" -void _expect_fully(UnionFind<> &uf, bool connected, int from = 0, int to = -1) { +void ExpectFully(UnionFind<> &uf, bool connected, int from = 0, int to = -1) { if (to == -1) to = uf.size(); for (int i = from; i < to; i++) @@ -42,27 +42,27 @@ TEST(UnionFindTest, ModifiedSizeTest) { TEST(UnionFindTest, Disconectivity) { UnionFind<> uf(10); - _expect_fully(uf, false); + ExpectFully(uf, false); } TEST(UnionFindTest, ConnectivityAlongChain) { UnionFind<> uf(10); for (unsigned int i = 1; i < uf.size(); i++) uf.connect(i - 1, i); - _expect_fully(uf, true); + ExpectFully(uf, true); } TEST(UnionFindTest, ConnectivityOnTree) { UnionFind<> uf(10); - _expect_fully(uf, false); + ExpectFully(uf, false); uf.connect(0, 1); uf.connect(0, 2); - _expect_fully(uf, true, 0, 3); - _expect_fully(uf, false, 2); + ExpectFully(uf, true, 0, 3); + ExpectFully(uf, false, 2); uf.connect(2, 3); - _expect_fully(uf, true, 0, 4); - _expect_fully(uf, false, 3); + ExpectFully(uf, true, 0, 4); + ExpectFully(uf, false, 3); } TEST(UnionFindTest, DisjointChains) { diff --git a/src/data_structures/map/rh_hashmap.hpp b/src/data_structures/map/rh_hashmap.hpp deleted file mode 100644 index 1948e9931..000000000 --- a/src/data_structures/map/rh_hashmap.hpp +++ /dev/null @@ -1,177 +0,0 @@ -#include - -#include "data_structures/map/rh_common.hpp" -#include "utils/assert.hpp" -#include "utils/crtp.hpp" -#include "utils/option_ptr.hpp" - -/** - * HashMap with RobinHood collision resolution policy. - * Single threaded. - * Entries are saved as pointers alligned to 8B. - * Entries must know thers key. - * D must have method const K & get_key() - * K must be comparable with ==. - * HashMap behaves as if it isn't owner of entries. - * BE CAREFUL - this structure assumes that the pointer to Data is 8-alligned! -*/ -template -class RhHashMap : public RhBase { - typedef RhBase base; - using base::array; - using base::index; - using base::capacity; - using base::count; - using typename base::Combined; - - void increase_size() { - size_t old_size = capacity; - auto a = array; - if (base::increase_size()) { - for (int i = 0; i < old_size; i++) { - if (a[i].valid()) { - insert(a[i].ptr()); - } - } - } - - free(a); - } - - public: - using base::RhBase; - - bool contains(const K &key) { return find(key).is_present(); } - - OptionPtr find(const K key) { - size_t mask = this->mask(); - size_t now = index(key, mask); - size_t off = 0; - size_t border = 8 <= capacity ? 8 : capacity; - - while (off < border) { - Combined other = array[now]; - if (other.valid()) { - auto other_off = other.off(); - if (other_off == off && key == other.ptr()->get_key()) { - // Found data. - return OptionPtr(other.ptr()); - - } else if (other_off < off) { // Other is rich - break; - } // Else other has equal or greater offset, so he is poor. - } else { - // Empty slot means that there is no searched data. - break; - } - - off++; - now = (now + 1) & mask; - } - return OptionPtr(); - } - - // Inserts element. Returns true if element wasn't in the map. - bool insert(D *data) { - permanent_assert(!(((uint64_t) static_cast(data) & 7)), - "Data is not 8-alligned."); - if (count < capacity) { - size_t mask = this->mask(); - auto key = std::ref(data->get_key()); - size_t now = index(key, mask); - size_t off = 0; - size_t border = 8 <= capacity ? 8 : capacity; - - while (off < border) { - Combined other = array[now]; - if (other.valid()) { - auto other_off = other.off(); - if (other_off == off && key == other.ptr()->get_key()) { - // Element already exists. - return false; - - } else if (other_off < off) { // Other is rich - // Set data. - array[now] = Combined(data, off); - - // Move other data to the higher indexes, - while (other.increment_off()) { - now = (now + 1) & mask; - auto tmp = array[now]; - array[now] = other; - other = tmp; - if (!other.valid()) { - count++; - return true; - } - } - data = other.ptr(); - break; // Cant insert removed element because it would - // be to far from his real place. - } // Else other has equal or greater offset, so he is poor. - } else { - // Data can be placed in this empty slot. - array[now] = Combined(data, off); - count++; - return true; - } - - off++; - now = (now + 1) & mask; - } - } - - // There isn't enough space for element pointed by data so whe must - // increase array. - increase_size(); - return insert(data); - } - - // Removes element. Returns removed element if it existed. - OptionPtr remove(const K &key) { - size_t mask = this->mask(); - size_t now = index(key, mask); - size_t off = 0; - size_t border = 8 <= capacity ? 8 : capacity; - - while (off < border) { - Combined other = array[now]; - if (other.valid()) { - auto other_off = other.off(); - auto other_ptr = other.ptr(); - if (other_off == off && key == other_ptr->get_key()) { // Found it - - auto before = now; - // Whe must move other elements one slot lower. - do { - // This is alright even for off=0 on found element - // because it wont be seen. - other.decrement_off_unsafe(); - - array[before] = other; - before = now; - now = (now + 1) & mask; - other = array[now]; - } while (other.valid() && - other.off() > 0); // Exit if whe encounter empty - // slot or data which is exactly - // in slot which it want's to be. - - array[before] = Combined(); - count--; - return OptionPtr(other_ptr); - - } else if (other_off < off) { // Other is rich - break; - } // Else other has equal or greater offset, so he is poor. - } else { - // If the element to be removed existed in map it would be here. - break; - } - - off++; - now = (now + 1) & mask; - } - return OptionPtr(); - } -}; diff --git a/src/data_structures/static_array.hpp b/src/data_structures/static_array.hpp deleted file mode 100644 index 91ecc952c..000000000 --- a/src/data_structures/static_array.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include "utils/assert.hpp" - -// data structure namespace short ds -// TODO: document strategy related to namespace naming -// (namespace names should be short but eazy to memorize) -namespace ds { - -// static array is data structure which size (capacity) can be known at compile -// time -// this data structure isn't concurrent -template -class static_array { - public: - // default constructor - static_array() {} - - // explicit constructor which populates the data array with - // initial values, array structure after initialization - // is N * [initial_value] - explicit static_array(const T &initial_value) { - for (size_t i = 0; i < size(); ++i) { - data[i] = initial_value; - } - } - - // returns array size - size_t size() const { return N; } - - // returns element reference on specific index - T &operator[](size_t index) { - debug_assert(index < N, "Index " << index << " must be less than " << N); - return data[index]; - } - - // returns const element reference on specific index - const T &operator[](size_t index) const { - debug_assert(index < N, "Index " << index << " must be less than " << N); - return data[index]; - } - - // returns begin iterator - T *begin() { return &data[0]; } - - // returns const begin iterator - const T *begin() const { return &data[0]; } - - // returns end iterator - T *end() { return &data[N]; } - - // returns const end iterator - const T *end() const { return &data[N]; } - - private: - T data[N]; -}; -} diff --git a/src/dbms/cleaner.cpp b/src/dbms/cleaner.cpp deleted file mode 100644 index e0503f0f6..000000000 --- a/src/dbms/cleaner.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "dbms/cleaner.hpp" - -#include -#include -#include - -#include "database/db_transaction.hpp" -#include "threading/thread.hpp" - -#include "logging/default.hpp" - -Cleaning::Cleaning(ConcurrentMap &dbs, - size_t cleaning_cycle) - : dbms(dbs), cleaning_cycle(cleaning_cycle) { - // Start the cleaning thread - cleaners.push_back( - std::make_unique([&, cleaning_cycle = cleaning_cycle ]() { - Logger logger = logging::log->logger("Cleaner"); - logger.info("Started with cleaning cycle of {} sec", cleaning_cycle); - - std::time_t last_clean = std::time(nullptr); - while (cleaning.load(std::memory_order_acquire)) { - std::time_t now = std::time(nullptr); - - // Maybe it's cleaning time. - if (now >= last_clean + cleaning_cycle) { - logger.info("Started cleaning cyle"); - - // Clean all databases - for (auto &db : dbs.access()) { - logger.info("Cleaning database \"{}\"", db.first); - DbTransaction t(db.second); - try { - logger.info("Cleaning edges"); - t.clean_edge_section(); - - logger.info("Cleaning vertices"); - t.clean_vertex_section(); - - logger.info("Cleaning garbage"); - db.second.garbage.clean(); - - } catch (const std::exception &e) { - logger.error("Error occured while cleaning database \"{}\"", - db.first); - logger.error("{}", e.what()); - } - // NOTE: Whe should commit even if error occured. - t.trans.commit(); - } - last_clean = now; - logger.info("Finished cleaning cyle"); - - } else { - // Cleaning isn't scheduled for now so i should sleep. - std::this_thread::sleep_for(std::chrono::seconds(1)); - } - } - })); -} - -Cleaning::~Cleaning() { - // Stop cleaning - cleaning.store(false, std::memory_order_release); - for (auto &t : cleaners) { - // Join with cleaners - t.get()->join(); - } -} diff --git a/src/dbms/cleaner.hpp b/src/dbms/cleaner.hpp deleted file mode 100644 index a3bd6908f..000000000 --- a/src/dbms/cleaner.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "database/graph_db.hpp" -#include "threading/thread.hpp" - -class Thread; - -class Cleaning { - public: - // How much sec is a cleaning_cycle in which cleaner will clean at most - // once. Starts cleaner thread. - Cleaning(ConcurrentMap &dbs, size_t cleaning_cycle); - - // Destroys this object after this thread joins cleaning thread. - ~Cleaning(); - - private: - ConcurrentMap &dbms; - - const size_t cleaning_cycle; - - std::vector> cleaners; - - // Should i continue cleaning. - std::atomic cleaning = {true}; -}; diff --git a/src/dbms/dbms.hpp b/src/dbms/dbms.hpp index 5c58268c3..acc08143a 100644 --- a/src/dbms/dbms.hpp +++ b/src/dbms/dbms.hpp @@ -57,13 +57,4 @@ class Dbms { // currently active database std::atomic active_db; - - // // Cleaning thread. - // TODO re-enable cleaning - // Cleaning cleaning = {dbs, CONFIG_INTEGER(config::CLEANING_CYCLE_SEC)}; - // - // // Snapshoting thread. - // TODO re-enable cleaning - // Snapshoter snapshoter = {dbs, - // CONFIG_INTEGER(config::SNAPSHOT_CYCLE_SEC)}; }; diff --git a/src/io/network/stream_reader.hpp b/src/io/network/stream_reader.hpp index e73369319..206bbe982 100644 --- a/src/io/network/stream_reader.hpp +++ b/src/io/network/stream_reader.hpp @@ -2,7 +2,7 @@ #include "io/network/stream_buffer.hpp" #include "io/network/stream_listener.hpp" -#include "memory/literals.hpp" +#include "utils/memory_literals.hpp" namespace io::network { diff --git a/src/memory/deferred_recycler.hpp b/src/memory/deferred_recycler.hpp deleted file mode 100644 index 2d8590eac..000000000 --- a/src/memory/deferred_recycler.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "recycler.hpp" - -template -class DeferredRecycler : Recycler { - public: - using Recycler::acquire; - - void recycle(T* item) { - auto guard = this->acquire_unique(); - dirty.push_back(item); - } - - void clean() { - auto guard = this->acquire_unique(); - - for (auto item : dirty) this->recycle_or_delete(item); - - dirty.clear(); - } - - private: - std::queue dirty; -}; diff --git a/src/memory/freelist.hpp b/src/memory/freelist.hpp deleted file mode 100644 index 6cd0c8c32..000000000 --- a/src/memory/freelist.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include - -#include "threading/sync/lockable.hpp" -#include "threading/sync/spinlock.hpp" - -template -class FreeList : Lockable { - public: - void swap(std::vector &dst) { std::swap(data, dst); } - - void add(T element) { - auto lock = this->acquire_unique(); - data.emplace_back(element); - } - - size_t size() const { return data.size(); } - - private: - std::vector data; -}; diff --git a/src/memory/lazy_gc.hpp b/src/memory/lazy_gc.hpp deleted file mode 100644 index eae9c0d06..000000000 --- a/src/memory/lazy_gc.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -// TODO: remove from here and from the project -#include -#include - -#include "threading/sync/lockable.hpp" -#include "utils/crtp.hpp" - -template -class LazyGC : public Crtp, public Lockable { - public: - // AddRef method should be called by a thread - // when the thread has to do something over - // object which has to be lazy cleaned when - // the thread finish it job - void AddRef() { - auto lock = this->acquire_unique(); - ++reference_count_; - } - - protected: - size_t reference_count_{0}; -}; diff --git a/src/memory/memory.hpp b/src/memory/memory.hpp deleted file mode 100644 index 58d3a5934..000000000 --- a/src/memory/memory.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - -#include "storage/model/edge.hpp" -#include "storage/model/record.hpp" -#include "storage/model/vertex.hpp" - -// TODO implement the memory engine using the allocator style allocation to -// make this class non-dependent on the memory allocation strategy - -// TODO implement real recycling of vertices and edges to improve performance -class MemoryEngine { - public: - template - T* create(Args&&... args) { - return new T(std::forward(args)...); - } - - template - T* allocate() { - return static_cast(malloc(sizeof(T))); - } - - template - void recycle(Record* record) { - recycle(&record->derived()); - } - - void recycle(Vertex* v) { delete v; } - - void recycle(Edge* e) { delete e; } - - private: - std::unique_lock acquire() { - return std::unique_lock(lock); - } - - SpinLock lock; -}; diff --git a/src/memory/recycler.hpp b/src/memory/recycler.hpp deleted file mode 100644 index 96c281e68..000000000 --- a/src/memory/recycler.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - -#include "threading/sync/lockable.hpp" -#include "threading/sync/spinlock.hpp" - -template > -class Recycler : public Lockable { - static constexpr size_t default_max_reserved = 100; - - public: - Recycler() = default; - Recycler(size_t max_reserved) : max_reserved(max_reserved) {} - - template - T* acquire(Args&&... args) { - auto guard = acquire_unique(); - return fetch_or_create(std::forward(args)...); - } - - void release(T* item) { - auto guard = acquire_unique(); - return recycle_or_delete(item); - } - - protected: - Allocator alloc; - size_t max_reserved{default_max_reserved}; - std::queue items; - - template - T* fetch_or_create(Args&&... args) { - return new T(std::forward(args)...); // todo refactor :D - } - - void recycle_or_delete(T* item) { - delete item; // todo refactor :D - } -}; diff --git a/src/mvcc/version_list.hpp b/src/mvcc/version_list.hpp index 06414aa2c..fd8ae469e 100644 --- a/src/mvcc/version_list.hpp +++ b/src/mvcc/version_list.hpp @@ -2,7 +2,6 @@ #include -#include "memory/lazy_gc.hpp" #include "storage/locking/record_lock.hpp" #include "threading/sync/lockable.hpp" #include "transactions/transaction.hpp" diff --git a/src/threading/global_pool.hpp b/src/threading/global_pool.hpp deleted file mode 100644 index a1a3b10ec..000000000 --- a/src/threading/global_pool.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "threading/pool.hpp" - -/** - * @brief - Singleton class which implements thread pool. - */ -class GlobalPool { - public: - // Guaranteed by the C++11 standard to be thread-safe. - static GlobalPool *getSingletonInstance() { - static GlobalPool instance; - return &instance; - } - - void run(Pool::task_t f) { thread_pool_.run(f); } - - GlobalPool(const GlobalPool &) = delete; - GlobalPool(const GlobalPool &&) = delete; - GlobalPool operator=(const GlobalPool &) = delete; - GlobalPool operator=(const GlobalPool &&) = delete; - - private: - GlobalPool() {} - Pool thread_pool_; -}; diff --git a/src/traversal/enums.hpp b/src/traversal/enums.hpp index 6d5cfa0dc..e6ff48921 100644 --- a/src/traversal/enums.hpp +++ b/src/traversal/enums.hpp @@ -24,11 +24,7 @@ namespace traversal_template { * it is mentioned that Vertex uniqueness can result in exponential performance * degradation. Figure out why and how. */ -enum class Uniqueness { - None, - Vertex, - Edge -}; +enum class Uniqueness { None, Vertex, Edge }; /** * Indicates how a path should be expanded using the traversal API. For the @@ -47,14 +43,13 @@ enum class Uniqueness { * * Note that this implies that a Path has direction (start and finish). */ -enum class Expansion { - Front, - Back -}; +enum class Expansion { Front, Back }; /** - * Indicates which relationships from the expansion vertex should be used to expand - * the path. Direction::In means that incoming relationships are used for expansion. + * Indicates which relationships from the expansion vertex should be used to + * expand + * the path. Direction::In means that incoming relationships are used for + * expansion. * * For example, for the given graph data: * @@ -64,13 +59,10 @@ enum class Expansion { * * p = (b) * - * Expansion (let's assume Expansion::Back) in the Direction::In would result in: + * Expansion (let's assume Expansion::Back) in the Direction::In would result + * in: * * q = (b)<-[]-(a) */ -enum class Direction { - In, - Out, - Both -}; +enum class Direction { In, Out, Both }; } diff --git a/src/traversal/path.hpp b/src/traversal/path.hpp index b26ccd3f3..45966bc9d 100644 --- a/src/traversal/path.hpp +++ b/src/traversal/path.hpp @@ -5,9 +5,9 @@ #pragma once -#include #include #include +#include #include "enums.hpp" #include "utils/assert.hpp" @@ -26,23 +26,19 @@ namespace traversal_template { * @tparam TVertex * @tparam TEdge */ -template +template class Path { -public: - + public: Path() {} - size_t Size() const { - return vertices_.size(); - } + size_t Size() const { return vertices_.size(); } friend std::ostream &operator<<(std::ostream &stream, const Path &path) { auto vertices_it = path.vertices_.begin(); auto vertices_end = path.vertices_.end(); auto edges_it = path.edges_.begin(); - if (vertices_it != vertices_end) - stream << *vertices_it++; + if (vertices_it != vertices_end) stream << *vertices_it++; while (vertices_it != vertices_end) @@ -67,7 +63,8 @@ public: * @return A reference to this same path. */ Path &Start(const TVertex &v) { - debug_assert(vertices_.size() == 0, "Can only start iteration on empty path"); + debug_assert(vertices_.size() == 0, + "Can only start iteration on empty path"); vertices_.push_back(v); return *this; } @@ -96,7 +93,8 @@ public: * Gets the last Vertex of this path. Fails if the path contains no elements. */ const TVertex &Back() const { - debug_assert(vertices_.size() > 0, "Can only get a Vertex on non-empty path"); + debug_assert(vertices_.size() > 0, + "Can only get a Vertex on non-empty path"); return vertices_.back(); } @@ -116,21 +114,23 @@ public: } /** - * Removes the last element from the path. Fails if the path contains no elements. + * Removes the last element from the path. Fails if the path contains no + * elements. */ void PopBack() { - debug_assert(vertices_.size() > 0, "Can only remove a vertex from a non-empty path"); + debug_assert(vertices_.size() > 0, + "Can only remove a vertex from a non-empty path"); vertices_.pop_back(); - if (vertices_.size() > 0) - edges_.pop_back(); + if (vertices_.size() > 0) edges_.pop_back(); } /** * Gets the first Vertex of this path. Fails if the path contains no elements. */ const TVertex &Front() const { - debug_assert(vertices_.size() > 0, "Can only get a vertex from a non-empty path"); + debug_assert(vertices_.size() > 0, + "Can only get a vertex from a non-empty path"); return vertices_.front(); } @@ -148,14 +148,15 @@ public: } /** - * Removes the first element from the path. Fails if the path contains no elements. + * Removes the first element from the path. Fails if the path contains no + * elements. */ void PopFront() { - debug_assert(vertices_.size() > 0, "Can only remove a vertex from a non-empty path"); + debug_assert(vertices_.size() > 0, + "Can only remove a vertex from a non-empty path"); vertices_.pop_front(); - if (vertices_.size() > 0) - edges_.pop_front(); + if (vertices_.size() > 0) edges_.pop_front(); } /** @@ -176,7 +177,7 @@ public: */ const auto &Edges() const { return edges_; } -private: + private: std::list vertices_; std::list edges_; }; @@ -192,7 +193,8 @@ private: template class Paths : public std::list>> { using Path = Path; -public: + + public: bool operator==(const Paths &other) const { return std::equal(this->begin(), this->end(), other.begin(), [](const std::reference_wrapper &p1, @@ -201,7 +203,7 @@ public: }); } - bool operator!=(const Paths &other) const { return !(*this == other);} + bool operator!=(const Paths &other) const { return !(*this == other); } friend std::ostream &operator<<(std::ostream &stream, const Paths &paths) { stream << "["; @@ -214,4 +216,3 @@ public: } }; } - diff --git a/src/traversal/templates.hpp b/src/traversal/templates.hpp index a0735fac1..697bd3f23 100644 --- a/src/traversal/templates.hpp +++ b/src/traversal/templates.hpp @@ -5,14 +5,13 @@ #pragma once -#include #include +#include #include "enums.hpp" #include "path.hpp" #include "utils/assert.hpp" - /** * This namespace contains traversal class templates that must * be parameterized with Vertex and Edge classes. This abstraction @@ -49,8 +48,7 @@ namespace traversal_template { */ template class UniquenessGroup { -public: - + public: UniquenessGroup(const Path &path) : current_path_(path) {} /** @@ -61,12 +59,10 @@ public: * @return */ bool Contains(const TVertex &vertex) const { - if (current_path_.Contains(vertex)) - return true; + if (current_path_.Contains(vertex)) return true; for (const auto &group : subgroups_) - if (group.get().Contains(vertex)) - return true; + if (group.get().Contains(vertex)) return true; return false; } @@ -79,12 +75,10 @@ public: * @return */ bool Contains(const TEdge &edge) const { - if (current_path_.Contains(edge)) - return true; + if (current_path_.Contains(edge)) return true; for (const auto &group : subgroups_) - if (group.get().Contains(edge)) - return true; + if (group.get().Contains(edge)) return true; return false; } @@ -95,14 +89,17 @@ public: * * @param subgroup */ - void Add(const UniquenessGroup &subgroup) { subgroups_.emplace_back(subgroup); } + void Add(const UniquenessGroup &subgroup) { + subgroups_.emplace_back(subgroup); + } -private: + private: // the currently traversed path of this uniqueness group // set by the BeginType const Path ¤t_path_; - std::vector>> subgroups_; + std::vector>> + subgroups_; }; /** @@ -116,14 +113,13 @@ private: * @tparam TVertex * @tparam TEdge */ -template +template class ExpandBaseType { - using TPath = Path; using VertexFilter = std::function; using EdgeFilter = std::function; -public: + public: /** * @return This expander's visitable's uniqueness group. */ @@ -131,8 +127,7 @@ public: return visitable_.UniquenessGroup(); } -protected: - + protected: // tracking last appended path elements during traversal TVertex const *current_vertex_ = nullptr; TEdge const *current_edge_ = nullptr; @@ -161,18 +156,15 @@ protected: * provided). * @param uniqueness Which kind of uniqueness should be applied. */ - ExpandBaseType(TVisitable &&visitable, - Expansion expansion, - Direction direction, - VertexFilter vertex_filter, - EdgeFilter edge_filter, - Uniqueness uniqueness - ) : visitable_(std::forward(visitable)), - expansion_(expansion), - direction_(direction), - vertex_filter_(vertex_filter), - edge_filter_(edge_filter), - uniqueness_(uniqueness) {} + ExpandBaseType(TVisitable &&visitable, Expansion expansion, + Direction direction, VertexFilter vertex_filter, + EdgeFilter edge_filter, Uniqueness uniqueness) + : visitable_(std::forward(visitable)), + expansion_(expansion), + direction_(direction), + vertex_filter_(vertex_filter), + edge_filter_(edge_filter), + uniqueness_(uniqueness) {} /** * Visits the given visitor with every expansion of the given path @@ -183,9 +175,9 @@ protected: * @param p */ void VisitExpansions(std::function visitor, TPath &p) { - // the start or end point of the vertex - const auto &origin_vertex = expansion_ == Expansion::Back ? p.Back() : p.Front(); + const auto &origin_vertex = + expansion_ == Expansion::Back ? p.Back() : p.Front(); if (direction_ == Direction::In || direction_ == Direction::Both) VisitExpansions(origin_vertex.in(), p, visitor, Direction::In); @@ -193,7 +185,7 @@ protected: VisitExpansions(origin_vertex.out(), p, visitor, Direction::Out); } -private: + private: /** * Helper method that handles path expansion and visiting w.r.t. * expansion params. @@ -209,21 +201,21 @@ private: * @param visitor * @param direction */ - template - void VisitExpansions(Edges &edges, - TPath &p, + template + void VisitExpansions(Edges &edges, TPath &p, std::function visitor, Direction direction) { - for (const TEdge &e : edges) { // edge filtering and uniqueness if (edge_filter_ && !edge_filter_(e)) continue; - if (uniqueness_ == Uniqueness::Edge && UniquenessGroup().Contains(e)) continue; + if (uniqueness_ == Uniqueness::Edge && UniquenessGroup().Contains(e)) + continue; // vertex filtering and uniqueness const TVertex &v = (direction == Direction::In) ? e.from() : e.to(); if (vertex_filter_ && !vertex_filter_(v)) continue; - if (uniqueness_ == Uniqueness::Vertex && UniquenessGroup().Contains(v))continue; + if (uniqueness_ == Uniqueness::Vertex && UniquenessGroup().Contains(v)) + continue; current_edge_ = &e; current_vertex_ = &v; @@ -257,15 +249,13 @@ private: * @tparam TVertex * @tparam TEdge */ -template +template class ExpandVariableType : public ExpandBaseType { - using TPath = Path; using VertexFilter = std::function; using EdgeFilter = std::function; - -public: + public: /** * For most params see the ExpandBaseType::ExpandBaseType documentation. * @@ -274,30 +264,26 @@ public: * @param max_length Maximum number of vertices in a path for it to be * visited. Exclusive. */ - ExpandVariableType(TVisitable &&visitable, - Expansion expansion, - Direction direction, - VertexFilter vertex_filter, - EdgeFilter edge_filter, - int min_length, - int max_length, - Uniqueness uniqueness) : - ExpandBaseType(std::forward(visitable), - expansion, direction, {}, edge_filter, uniqueness), - min_length_(min_length), - max_length_(max_length), - current_vertex_filter_(vertex_filter) { - } + ExpandVariableType(TVisitable &&visitable, Expansion expansion, + Direction direction, VertexFilter vertex_filter, + EdgeFilter edge_filter, int min_length, int max_length, + Uniqueness uniqueness) + : ExpandBaseType( + std::forward(visitable), expansion, direction, {}, + edge_filter, uniqueness), + min_length_(min_length), + max_length_(max_length), + current_vertex_filter_(vertex_filter) {} /** - * Calls the given visitor function once for every path this traversal generates. + * Calls the given visitor function once for every path this traversal + * generates. * * @param visitor */ void Visit(std::function visitor) { - this->visitable_.Visit([this, &visitor](TPath &p) { - VisitRecursive(visitor, p, p.Size()); - }); + this->visitable_.Visit( + [this, &visitor](TPath &p) { VisitRecursive(visitor, p, p.Size()); }); } /** @@ -306,10 +292,8 @@ public: * * @return An expansion that generates paths one traversal longer. */ - auto Expand(Expansion expansion, - Direction direction, - VertexFilter vertex_filter = {}, - EdgeFilter edge_filter = {}); + auto Expand(Expansion expansion, Direction direction, + VertexFilter vertex_filter = {}, EdgeFilter edge_filter = {}); /** * Expands from this expansion along a variable number traversal. @@ -317,13 +301,10 @@ public: * * @return An expansion that generates paths variable length longer. */ - auto ExpandVariable( - Expansion expansion, - Direction direction, - VertexFilter vertex_filter = {}, - EdgeFilter edge_filter = {}, - int min_length = 0, - int max_length = 1000); + auto ExpandVariable(Expansion expansion, Direction direction, + VertexFilter vertex_filter = {}, + EdgeFilter edge_filter = {}, int min_length = 0, + int max_length = 1000); /** * Returns a reference to the vertex currently being traversed @@ -331,7 +312,9 @@ public: * TRAVERSAL!!! */ const TVertex &CurrentVertex() const { - debug_assert(this->current_vertex_ != nullptr, "Current vertex not set, function most likely called outside of traversal"); + debug_assert(this->current_vertex_ != nullptr, + "Current vertex not set, function most likely called outside " + "of traversal"); return *this->current_vertex_; } @@ -341,18 +324,22 @@ public: * TRAVERSAL!!! */ const std::list &CurrentEdges() const { - debug_assert(this->current_edge_ != nullptr, "Current edge not set, function most likely called outside of traversal"); + debug_assert(this->current_edge_ != nullptr, + "Current edge not set, function most likely called outside of " + "traversal"); return current_edges_; } -private: + private: // see constructor documentation for member var explanation const int min_length_; const int max_length_; - // the expand variable has another vertex filter used only on the last path element + // the expand variable has another vertex filter used only on the last path + // element // because traversal is done recursively using superclass functionality, - // so we give an empty filter to superclass so it does not end traversal, and use + // so we give an empty filter to superclass so it does not end traversal, and + // use // this filter to see if we actually need to visit the path or not const VertexFilter current_vertex_filter_; @@ -369,22 +356,25 @@ private: * @param p_start_size The size of the path before variable-length expansion. * It's necessary to keep track of it because min and max length are * evaluated against how much this traversal generated, not against the - * actual path length (there could have been plan expansions before this variable length). + * actual path length (there could have been plan expansions before this + * variable length). */ - void VisitRecursive(std::function visitor, TPath &p, const size_t p_start_size) { - debug_assert(p.Size() >= p_start_size, "Current path must be greater then start size"); + void VisitRecursive(std::function visitor, TPath &p, + const size_t p_start_size) { + debug_assert(p.Size() >= p_start_size, + "Current path must be greater then start size"); size_t recursion_size = p.Size() - p_start_size; // only append to current_edges once the first traversal happened - if (recursion_size > 0) - current_edges_.emplace_back(*this->current_edge_); + if (recursion_size > 0) current_edges_.emplace_back(*this->current_edge_); - if (recursion_size >= min_length_ && (!current_vertex_filter_ || current_vertex_filter_(*this->current_vertex_))) + if (recursion_size >= min_length_ && + (!current_vertex_filter_ || + current_vertex_filter_(*this->current_vertex_))) visitor(p); - if (recursion_size >= max_length_ - 1) - return; + if (recursion_size >= max_length_ - 1) return; // a lambda we'll inject to ExpandVisit, that calls this function // with the expanded path @@ -394,8 +384,7 @@ private: this->VisitExpansions(recursive_visitor, p); - if (recursion_size > 0) - current_edges_.pop_back(); + if (recursion_size > 0) current_edges_.pop_back(); } }; @@ -409,36 +398,32 @@ private: * @tparam TVertex * @tparam TEdge */ -template +template class ExpandType : public ExpandBaseType { - using TPath = Path; using VertexFilter = std::function; using EdgeFilter = std::function; - -public: + public: /** * For all params see the ExpandBaseType::ExpandBaseType documentation. */ - ExpandType(TVisitable &&visitable, - Expansion expansion, - Direction direction, - VertexFilter vertex_filter, - EdgeFilter edge_filter, - Uniqueness uniqueness) : - ExpandBaseType(std::forward(visitable), - expansion, direction, vertex_filter, edge_filter, uniqueness) {} + ExpandType(TVisitable &&visitable, Expansion expansion, Direction direction, + VertexFilter vertex_filter, EdgeFilter edge_filter, + Uniqueness uniqueness) + : ExpandBaseType( + std::forward(visitable), expansion, direction, + vertex_filter, edge_filter, uniqueness) {} /** - * Calls the given visitor function once for every path this traversal generates. + * Calls the given visitor function once for every path this traversal + * generates. * * @param visitor */ void Visit(std::function visitor) { - this->visitable_.Visit([this, &visitor](TPath &p) { - this->VisitExpansions(visitor, p); - }); + this->visitable_.Visit( + [this, &visitor](TPath &p) { this->VisitExpansions(visitor, p); }); } /** @@ -447,7 +432,9 @@ public: * TRAVERSAL!!! */ const TVertex &CurrentVertex() const { - debug_assert(this->current_vertex_ != nullptr, "Current vertex not set, function most likely called outside of traversal"); + debug_assert(this->current_vertex_ != nullptr, + "Current vertex not set, function most likely called outside " + "of traversal"); return *this->current_vertex_; } @@ -457,7 +444,9 @@ public: * TRAVERSAL!!! */ const TEdge &CurrentEdge() const { - debug_assert(this->current_edge_ != nullptr, "Current edge not set, function most likely called outside of traversal"); + debug_assert(this->current_edge_ != nullptr, + "Current edge not set, function most likely called outside of " + "traversal"); return *this->current_edge_; } @@ -467,12 +456,11 @@ public: * * @return An expansion that generates paths one traversal longer. */ - auto Expand(Expansion expansion, - Direction direction, - VertexFilter vertex_filter = {}, - EdgeFilter edge_filter = {}) { + auto Expand(Expansion expansion, Direction direction, + VertexFilter vertex_filter = {}, EdgeFilter edge_filter = {}) { return ExpandType &, TVertex, TEdge>( - *this, expansion, direction, vertex_filter, edge_filter, this->uniqueness_); + *this, expansion, direction, vertex_filter, edge_filter, + this->uniqueness_); } /** @@ -481,15 +469,14 @@ public: * * @return An expansion that generates paths variable length longer. */ - auto ExpandVariable( - Expansion expansion, - Direction direction, - VertexFilter vertex_filter = {}, - EdgeFilter edge_filter = {}, - int min_length = 0, - int max_length = 1000) { - return ExpandVariableType &, TVertex, TEdge>( - *this, expansion, direction, vertex_filter, edge_filter, min_length, max_length, this->uniqueness_); + auto ExpandVariable(Expansion expansion, Direction direction, + VertexFilter vertex_filter = {}, + EdgeFilter edge_filter = {}, int min_length = 0, + int max_length = 1000) { + return ExpandVariableType &, + TVertex, TEdge>( + *this, expansion, direction, vertex_filter, edge_filter, min_length, + max_length, this->uniqueness_); } }; @@ -500,17 +487,17 @@ public: * @tparam TVertex * @tparam TEdge */ -template +template class BeginType { - using TPath = Path; using VertexFilter = std::function; using EdgeFilter = std::function; -public: - - BeginType(const TIterable &vertices, VertexFilter vertex_filter) : - vertices_(vertices), vertex_filter_(vertex_filter), uniqueness_group_(path) {} + public: + BeginType(const TIterable &vertices, VertexFilter vertex_filter) + : vertices_(vertices), + vertex_filter_(vertex_filter), + uniqueness_group_(path) {} /** * Calls the visitor with a path containing a single vertex @@ -521,9 +508,7 @@ public: */ void Visit(std::function visitor) { for (const TVertex &v : vertices_) { - - if (vertex_filter_ && !vertex_filter_(v)) - continue; + if (vertex_filter_ && !vertex_filter_(v)) continue; path.Start(v); visitor(path); @@ -531,7 +516,6 @@ public: } } - /** * The UniquenessGroup of this BeginType (the only one that * exists for all the expansions from this Begin). @@ -546,7 +530,9 @@ public: * TRAVERSAL!!! */ const TVertex &CurrentVertex() const { - debug_assert(path.Size() > 0, "Current path is empty, function most likely called outside of traversal"); + debug_assert(path.Size() > 0, + "Current path is empty, function most likely called outside " + "of traversal"); return path.Front(); } @@ -556,10 +542,8 @@ public: * * @return An expansion that generates paths one traversal longer. */ - auto Expand(Expansion expansion, - Direction direction, - VertexFilter vertex_filter = {}, - EdgeFilter edge_filter = {}, + auto Expand(Expansion expansion, Direction direction, + VertexFilter vertex_filter = {}, EdgeFilter edge_filter = {}, Uniqueness uniqueness = Uniqueness::Edge) { return ExpandType &, TVertex, TEdge>( *this, expansion, direction, vertex_filter, edge_filter, uniqueness); @@ -571,21 +555,21 @@ public: * * @return An expansion that generates paths variable length longer. */ - auto ExpandVariable( - Expansion expansion, - Direction direction, - VertexFilter vertex_filter = {}, - EdgeFilter edge_filter = {}, - int min_length = 1, - int max_length = 1000, - Uniqueness uniqueness = Uniqueness::Edge) { - return ExpandVariableType &, TVertex, TEdge>( - *this, expansion, direction, vertex_filter, edge_filter, min_length, max_length, uniqueness); + auto ExpandVariable(Expansion expansion, Direction direction, + VertexFilter vertex_filter = {}, + EdgeFilter edge_filter = {}, int min_length = 1, + int max_length = 1000, + Uniqueness uniqueness = Uniqueness::Edge) { + return ExpandVariableType &, TVertex, + TEdge>(*this, expansion, direction, vertex_filter, + edge_filter, min_length, max_length, + uniqueness); } -private: + private: const TIterable &vertices_; - // the BeingType has only one path that gets appended to and emitted to visitors + // the BeingType has only one path that gets appended to and emitted to + // visitors TPath path; const VertexFilter vertex_filter_; // TODO review: why do I have to have namespace:: here??? @@ -601,7 +585,7 @@ private: * * @return A BeginType. */ -template +template auto Begin(const TIterable &vertices, std::function vertex_filter = {}) { return BeginType(vertices, vertex_filter); @@ -610,14 +594,14 @@ auto Begin(const TIterable &vertices, /** * Creates a start point for a recursion of Cartesian wrappers. */ -template +template class CartesianUnaryType { using TPath = Path; using TPaths = Paths; -public: - CartesianUnaryType(TVisitable &&visitable) : - visitable_(std::forward(visitable)) {} + public: + CartesianUnaryType(TVisitable &&visitable) + : visitable_(std::forward(visitable)) {} void Visit(std::function visitor) const { TPaths paths; @@ -628,29 +612,35 @@ public: }); } -private: + private: const TVisitable visitable_; }; /** * Provides means to visit a cartesian product of traversals. * - * @tparam TVisitableFirst A visitable whose visitor accepts a list of path reference (recursion down). - * @tparam TVisitableOthers Visitables whose visitor accepts a single path reference. + * @tparam TVisitableFirst A visitable whose visitor accepts a list of path + * reference (recursion down). + * @tparam TVisitableOthers Visitables whose visitor accepts a single path + * reference. */ -template +template class CartesianBinaryType { using TPath = Path; using TPaths = Paths; -public: + public: /** - * @tparam visitable_first A visitable whose visitor accepts a list of path reference (recursion down). - * @tparam visitable_others Visitable whose visitor accepts a single path reference. + * @tparam visitable_first A visitable whose visitor accepts a list of path + * reference (recursion down). + * @tparam visitable_others Visitable whose visitor accepts a single path + * reference. */ - CartesianBinaryType(TVisitableFirst &&visitable_first, TVisitableOthers &&visitable_others) : - visitable_first_(std::forward(visitable_first)), - visitable_others_(std::forward(visitable_others)) {} + CartesianBinaryType(TVisitableFirst &&visitable_first, + TVisitableOthers &&visitable_others) + : visitable_first_(std::forward(visitable_first)), + visitable_others_(std::forward(visitable_others)) {} /** * Calls the given visitor with a list of reference wrappers to Paths @@ -659,7 +649,6 @@ public: * @param visitor */ void Visit(std::function visitor) const { - // TODO currently cartesian product does NOT check for uniqueness // for example between edges in the emitted path combinations @@ -672,14 +661,15 @@ public: }); } -private: + private: const TVisitableFirst visitable_first_; const TVisitableOthers visitable_others_; }; /** * Creates an object that can be visited with a function that accepts a list - * of path reference wrappers. That function will be called one for every element + * of path reference wrappers. That function will be called one for every + * element * of a cartesian product of the given visitables (that emit paths). * * @tparam TVisitableFirst A visitable that emits paths. @@ -688,15 +678,16 @@ private: * @param others An arbitrary number of visitables that emit paths. * @return See above. */ -template +template auto Cartesian(TVisitable &&visitable) { - return CartesianUnaryType(std::forward(visitable)); - + return CartesianUnaryType( + std::forward(visitable)); } /** * Creates an object that can be visited with a function that accepts a list - * of path reference wrappers. That function will be called one for every element + * of path reference wrappers. That function will be called one for every + * element * of a cartesian product of the given visitables (that emit paths). * * @tparam TVisitableFirst A visitable that emits paths. @@ -705,34 +696,32 @@ auto Cartesian(TVisitable &&visitable) { * @param others An arbitrary number of visitables that emit paths. * @return See above. */ -template +template auto Cartesian(TVisitableFirst &&first, TVisitableOthers &&... others) { - return CartesianBinaryType(others)...)), - Vertex, Edge>( - std::forward(first), - Cartesian(std::forward(others)...) - ); + return CartesianBinaryType< + TVisitableFirst, + decltype(Cartesian(std::forward(others)...)), Vertex, + Edge>(std::forward(first), + Cartesian(std::forward(others)...)); } -template -auto ExpandVariableType::Expand(Expansion expansion, - Direction direction, - VertexFilter vertex_filter, - EdgeFilter edge_filter) { - return ExpandType &, TVertex, TEdge>( - *this, expansion, direction, vertex_filter, edge_filter, this->uniqueness_); +template +auto ExpandVariableType::Expand( + Expansion expansion, Direction direction, VertexFilter vertex_filter, + EdgeFilter edge_filter) { + return ExpandType &, TVertex, + TEdge>(*this, expansion, direction, vertex_filter, + edge_filter, this->uniqueness_); } -template +template auto ExpandVariableType::ExpandVariable( - Expansion expansion, - Direction direction, - VertexFilter vertex_filter, - EdgeFilter edge_filter, - int min_length, - int max_length) { - return ExpandVariableType &, TVertex, TEdge>( - *this, expansion, direction, vertex_filter, edge_filter, min_length, max_length, this->uniqueness_); + Expansion expansion, Direction direction, VertexFilter vertex_filter, + EdgeFilter edge_filter, int min_length, int max_length) { + return ExpandVariableType &, + TVertex, TEdge>( + *this, expansion, direction, vertex_filter, edge_filter, min_length, + max_length, this->uniqueness_); } - } diff --git a/src/traversal/traversal.hpp b/src/traversal/traversal.hpp index e2043d59d..429471761 100644 --- a/src/traversal/traversal.hpp +++ b/src/traversal/traversal.hpp @@ -9,8 +9,8 @@ #include "path.hpp" #include "templates.hpp" -#include "storage/vertex_accessor.hpp" #include "storage/edge_accessor.hpp" +#include "storage/vertex_accessor.hpp" /** * A specialization of the "traversal" namespace that uses @@ -25,34 +25,36 @@ using Paths = traversal_template::Paths; /** * Specialization of the traversal_template::Begin function. */ -template -auto Begin(const TCollection &vertices, std::function vertex_filter = {}) { -return traversal_template::Begin(vertices, vertex_filter); +template +auto Begin(const TCollection &vertices, + std::function vertex_filter = {}) { + return traversal_template::Begin( + vertices, vertex_filter); } /** * Specialization of the traversal_template::Cartesian function that accepts * a single argument. */ -template +template auto Cartesian(TVisitable &&visitable) { - return traversal_template::Cartesian( + return traversal_template::Cartesian( std::forward(visitable)); } - /** * Specialization of the traversal_template::Cartesian function that accepts * multiple arguments. */ -template +template auto Cartesian(TVisitableFirst &&first, TVisitableOthers &&... others) { - return traversal_template::CartesianBinaryType(others)...)), + return traversal_template::CartesianBinaryType< + TVisitableFirst, + decltype(Cartesian(std::forward(others)...)), VertexAccessor, EdgeAccessor>( std::forward(first), - Cartesian(std::forward(others)...) - ); + Cartesian(std::forward(others)...)); } } diff --git a/src/memory/literals.hpp b/src/utils/memory_literals.hpp similarity index 100% rename from src/memory/literals.hpp rename to src/utils/memory_literals.hpp diff --git a/src/utils/timer/timer.hpp b/src/utils/timer.hpp similarity index 100% rename from src/utils/timer/timer.hpp rename to src/utils/timer.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1176ea10a..576c48c88 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,8 +4,6 @@ project(${project_name}_tests) enable_testing() -include_directories(${catch_source_dir}/include) - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test_results/unit) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test_results/benchmark) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test_results/property_based) diff --git a/tests/concurrent/common.h b/tests/concurrent/common.hpp similarity index 95% rename from tests/concurrent/common.h rename to tests/concurrent/common.hpp index 7802393ea..14f994072 100644 --- a/tests/concurrent/common.h +++ b/tests/concurrent/common.hpp @@ -11,7 +11,6 @@ #include "data_structures/concurrent/concurrent_map.hpp" #include "data_structures/concurrent/concurrent_set.hpp" #include "data_structures/concurrent/skiplist.hpp" -#include "data_structures/static_array.hpp" #include "utils/assert.hpp" #include "utils/sysinfo/memory.hpp" @@ -73,7 +72,7 @@ void check_size_list(S &acc, long long size) { for ([[gnu::unused]] auto elem : acc) { ++iterator_counter; } - permanent_assert(iterator_counter == size, + permanent_assert(static_cast(iterator_counter) == size, "Iterator count should be " << size << ", but size is " << iterator_counter); } @@ -91,7 +90,7 @@ void check_size(typename S::Accessor &acc, long long size) { for ([[gnu::unused]] auto elem : acc) { ++iterator_counter; } - permanent_assert(iterator_counter == size, + permanent_assert(static_cast(iterator_counter) == size, "Iterator count should be " << size << ", but size is " << iterator_counter); } @@ -111,7 +110,7 @@ void check_order(typename S::Accessor &acc) { } void check_zero(size_t key_range, long array[], const char *str) { - for (int i = 0; i < key_range; i++) { + for (int i = 0; i < static_cast(key_range); i++) { permanent_assert(array[i] == 0, str << " doesn't hold it's guarantees. It has " << array[i] << " extra elements."); @@ -119,7 +118,7 @@ void check_zero(size_t key_range, long array[], const char *str) { } void check_set(DynamicBitset<> &db, std::vector &set) { - for (int i = 0; i < set.size(); i++) { + for (int i = 0; i < static_cast(set.size()); i++) { permanent_assert(!(set[i] ^ db.at(i)), "Set constraints aren't fullfilled."); } @@ -177,7 +176,7 @@ std::vector collect_set( std::vector set; for (auto &data : collect(futures)) { set.resize(data.second.size()); - for (int i = 0; i < data.second.size(); i++) { + for (int i = 0; i < static_cast(data.second.size()); i++) { set[i] = set[i] | data.second[i]; } } diff --git a/tests/concurrent/conncurent_list.cpp b/tests/concurrent/conncurent_list.cpp index cd31a62d7..7f248d638 100644 --- a/tests/concurrent/conncurent_list.cpp +++ b/tests/concurrent/conncurent_list.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t key_range = 1e2; diff --git a/tests/concurrent/dynamic_bitset.cpp b/tests/concurrent/dynamic_bitset.cpp index 378cd3ef5..0fb14c321 100644 --- a/tests/concurrent/dynamic_bitset.cpp +++ b/tests/concurrent/dynamic_bitset.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t op_per_thread = 1e5; diff --git a/tests/concurrent/dynamic_bitset_clear_n.cpp b/tests/concurrent/dynamic_bitset_clear_n.cpp index d88aae158..a4ff5a48b 100644 --- a/tests/concurrent/dynamic_bitset_clear_n.cpp +++ b/tests/concurrent/dynamic_bitset_clear_n.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 4); constexpr size_t op_per_thread = 1e5; diff --git a/tests/concurrent/dynamic_bitset_set.cpp b/tests/concurrent/dynamic_bitset_set.cpp index d680913cb..6544ea7a3 100644 --- a/tests/concurrent/dynamic_bitset_set.cpp +++ b/tests/concurrent/dynamic_bitset_set.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t op_per_thread = 1e5; diff --git a/tests/concurrent/dynamic_bitset_set_n.cpp b/tests/concurrent/dynamic_bitset_set_n.cpp index c6636e8fd..c2b2acda8 100644 --- a/tests/concurrent/dynamic_bitset_set_n.cpp +++ b/tests/concurrent/dynamic_bitset_set_n.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 4); constexpr size_t op_per_thread = 1e5; diff --git a/tests/concurrent/measure_time.cpp b/tests/concurrent/measure_time.cpp index 7a3d6f764..f20d3f10d 100644 --- a/tests/concurrent/measure_time.cpp +++ b/tests/concurrent/measure_time.cpp @@ -5,7 +5,7 @@ #include #include "utils/assert.hpp" -#include "utils/timer/timer.hpp" +#include "utils/timer.hpp" using namespace std::chrono_literals; using namespace utils; diff --git a/tests/concurrent/sl_insert.cpp b/tests/concurrent/sl_insert.cpp index 355f2d516..b3c7665d4 100644 --- a/tests/concurrent/sl_insert.cpp +++ b/tests/concurrent/sl_insert.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); diff --git a/tests/concurrent/sl_insert_competetive.cpp b/tests/concurrent/sl_insert_competetive.cpp index a58baf0f7..93a863781 100644 --- a/tests/concurrent/sl_insert_competetive.cpp +++ b/tests/concurrent/sl_insert_competetive.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t elems_per_thread = 100000; diff --git a/tests/concurrent/sl_map.cpp b/tests/concurrent/sl_map.cpp index 27d45c9a2..e4e67b162 100644 --- a/tests/concurrent/sl_map.cpp +++ b/tests/concurrent/sl_map.cpp @@ -1,19 +1,19 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t elems_per_thread = 1e5; // TODO: document the test -int main(int argc, char **argv) { +int main(int, char **argv) { google::InitGoogleLogging(argv[0]); memory_check(THREADS_NO, [&] { - ds::static_array threads; + std::vector threads; map_t skiplist; // put THREADS_NO * elems_per_thread items to the skiplist for (size_t thread_i = 0; thread_i < THREADS_NO; ++thread_i) { - threads[thread_i] = std::thread( + threads.emplace_back( [&skiplist](size_t start, size_t end) { auto accessor = skiplist.access(); for (size_t elem_i = start; elem_i < end; ++elem_i) { @@ -54,8 +54,8 @@ int main(int argc, char **argv) { // check size { auto accessor = skiplist.access(); - permanent_assert(accessor.size() == 0, - "Size should be 0, but size is " << accessor.size()); + permanent_assert(accessor.size() == 0, "Size should be 0, but size is " + << accessor.size()); } // check count diff --git a/tests/concurrent/sl_memory.cpp b/tests/concurrent/sl_memory.cpp index adf9e55cd..9877be94a 100644 --- a/tests/concurrent/sl_memory.cpp +++ b/tests/concurrent/sl_memory.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t elements = 2e6; diff --git a/tests/concurrent/sl_memory_leak.cpp b/tests/concurrent/sl_memory_leak.cpp index 4f8ac8b24..3215f7ee4 100644 --- a/tests/concurrent/sl_memory_leak.cpp +++ b/tests/concurrent/sl_memory_leak.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 1); constexpr size_t elems_per_thread = 16e5; @@ -9,16 +9,16 @@ constexpr size_t elems_per_thread = 16e5; // 2. analyse this code // 3. fix the memory leak // 4. write proper test -int main(int argc, char **argv) { +int main(int, char **argv) { google::InitGoogleLogging(argv[0]); memory_check(THREADS_NO, [&] { - ds::static_array threads; + std::vector threads; map_t skiplist; // put THREADS_NO * elems_per_thread items to the skiplist for (size_t thread_i = 0; thread_i < THREADS_NO; ++thread_i) { - threads[thread_i] = std::thread( + threads.emplace_back( [&skiplist](size_t start, size_t end) { auto accessor = skiplist.access(); for (size_t elem_i = start; elem_i < end; ++elem_i) { @@ -59,8 +59,8 @@ int main(int argc, char **argv) { // check size { auto accessor = skiplist.access(); - permanent_assert(accessor.size() == 0, - "Size should be 0, but size is " << accessor.size()); + permanent_assert(accessor.size() == 0, "Size should be 0, but size is " + << accessor.size()); } // check count diff --git a/tests/concurrent/sl_remove_competetive.cpp b/tests/concurrent/sl_remove_competetive.cpp index 0e2793995..0fc5aa1e5 100644 --- a/tests/concurrent/sl_remove_competetive.cpp +++ b/tests/concurrent/sl_remove_competetive.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t op_per_thread = 1e5; diff --git a/tests/concurrent/sl_remove_disjoint.cpp b/tests/concurrent/sl_remove_disjoint.cpp index 3a88ee1e4..50c392eaf 100644 --- a/tests/concurrent/sl_remove_disjoint.cpp +++ b/tests/concurrent/sl_remove_disjoint.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t key_range = 1e5; diff --git a/tests/concurrent/sl_remove_joint.cpp b/tests/concurrent/sl_remove_joint.cpp index 2ced1e974..9e0b33548 100644 --- a/tests/concurrent/sl_remove_joint.cpp +++ b/tests/concurrent/sl_remove_joint.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t key_range = 1e4; diff --git a/tests/concurrent/sl_set.cpp b/tests/concurrent/sl_set.cpp index e8493ea54..dcfac1fc4 100644 --- a/tests/concurrent/sl_set.cpp +++ b/tests/concurrent/sl_set.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t key_range = 1e4; diff --git a/tests/concurrent/sl_simulation.cpp b/tests/concurrent/sl_simulation.cpp index 839732477..2b779557d 100644 --- a/tests/concurrent/sl_simulation.cpp +++ b/tests/concurrent/sl_simulation.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.hpp" constexpr size_t THREADS_NO = std::min(max_no_threads, 8); constexpr size_t key_range = 1e5;