diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6bc7f76 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "clang.cflags": [ + "-std=c++17", + "-I${workspaceRoot}/include" + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index c112d61..55a6ddb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CXX= clang++-8 +CXX= clang++-10 CXXFLAGS= --std=c++17 -O0 -pthread -DFUZZ_STRENGTH=500000 \ -Wno-unknown-attributes \ -g -fprofile-instr-generate -fcoverage-mapping diff --git a/include/gp/pair.hpp b/include/gp/pair.hpp new file mode 100644 index 0000000..397cabb --- /dev/null +++ b/include/gp/pair.hpp @@ -0,0 +1,72 @@ +#pragma once +#include "gp/algorithm/move.hpp" + +namespace gp{ + template + struct pair{ + T1 first; + T2 second; + + pair() : first(), second() {} + + pair(const T1& a, const T2& b) : first(a), second(b) {} + + pair(pair&& v) + : first(gp::move(v.first)) + , second(gp::move(v.second)) + {} + + template + pair(U1&& a, U2&& b) + : first(gp::forward(a)) + , second(gp::forward(b)) + {} + + template + pair(pair&& v) + : first(gp::move(v.first)) + , second(gp::move(v.second)) + {} + + pair& operator=(pair&& v) + { + first = gp::move(v.first); + second = gp::move(v.second); + return *this; + } + + bool operator==(const pair& rhs) { + return first == rhs.first and second == rhs.second; + } + + bool operator!=(const pair& rhs) { + return first != rhs.first or second != rhs.second; + } + + bool operator<=(const pair& rhs) { + if(first > rhs.first) { + return false; + } else if(first == rhs.first) { + return second <= rhs.second; + } + return true; + } + + bool operator>=(const pair& rhs) { + if(first < rhs.first) { + return false; + } else if(first == rhs.first) { + return second >= rhs.second; + } + return true; + } + + bool operator<(const pair& rhs) { + return !(*this >= rhs); + } + + bool operator>(const pair& rhs) { + return !(*this <= rhs); + } + }; +} \ No newline at end of file diff --git a/tests.cpp b/tests.cpp index 70d7c82..5d167d9 100644 --- a/tests.cpp +++ b/tests.cpp @@ -4,6 +4,7 @@ #include "gp_test.cpp" #include "bloomfilter.cpp" #include "quotient_filter.cpp" +#include "pair_test.cpp" #include alignas(2048) gp::array static_mapper::store; diff --git a/tests/pair_test.cpp b/tests/pair_test.cpp new file mode 100644 index 0000000..ac3b139 --- /dev/null +++ b/tests/pair_test.cpp @@ -0,0 +1,37 @@ +#include "test_scaffold.h" +#include +#include +#include "gp/pair.hpp" + +typedef std::mt19937_64 cheap_rand; + +struct pair_test : public test_scaffold { + uint32_t seed; + + pair_test() { + seed = std::random_device{}(); + name = __FILE__ ":1_seed"; + name += std::to_string(seed); + } + + virtual int run() { + + cheap_rand setter(seed); + cheap_rand getter(seed); + + gp::pair v{0, "zero"}; + bool result = true; + + for(int i = 0 ; i < 100; i++) + { + auto a = setter(); + auto b = setter(); + v = gp::pair(a, std::to_string(a)); + result = gp::pair(b, std::to_string(b)) == v ? result : false; + } + + return !result; + } +}; + +append_test dummy_rsly21r43(new pair_test{}); \ No newline at end of file