diff --git a/Makefile b/Makefile index c3df7ef..f664f5e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ all: tests tests: bin/tests LLVM_PROFILE_FILE="./bin/tests.profraw" ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./bin/tests @llvm-profdata merge -sparse ./bin/tests.profraw -o ./bin/tests.profdata - @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp - @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' + @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/enveloppe/*.hpp include/gp/allocator/*.hpp + @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/enveloppe/*.hpp include/gp/allocator/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' bin/tests: tests.cpp $(wildcard tests/*.cpp) $(wildcard include/*.hpp) ./tests/test_scaffold.h @mkdir -p $(@D) diff --git a/include/gp/algorithm/foreach.hpp b/include/gp/algorithm/foreach.hpp index 34ee689..44b47e4 100644 --- a/include/gp/algorithm/foreach.hpp +++ b/include/gp/algorithm/foreach.hpp @@ -18,4 +18,11 @@ namespace gp{ f(elem); } } + + template + void fill(range& range_v, T value) { + for(auto& elem : range_v) { + elem = value; + } + } } \ No newline at end of file diff --git a/include/gp/array.hpp b/include/gp/array.hpp index e6f55ee..fcf7399 100644 --- a/include/gp/array.hpp +++ b/include/gp/array.hpp @@ -14,65 +14,6 @@ namespace gp{ using associated_riterator = pointer_iterator; using associated_const_riterator = const_pointer_iterator; - array() - : ary() - {} - - array(const array& oth) - { - auto it_l = begin(); - auto it_o = oth.cbegin(); - for(size_t i = 0; i < sz; ++i) - { - new(&*(it_l++)) T(*(it_o++)); - } - } - - template - array(U&& ...values) - : ary{gp::forward((T&&)values)...} - {} - - array(array&& values) - { - gp::move_uninitialized( - values, - *this - ); - } - - array(T (& oth)[sz]) { - gp::move_uninitialized( - gp::nameless_range(oth, oth+sz), - gp::nameless_range(begin(), end()) - ); - } - - array(T (&& oth)[sz]) { - gp::move_uninitialized( - gp::nameless_range((T*)oth, (T*)oth+sz), - gp::nameless_range(begin(), end()) - ); - } - - array& operator=(array& oth) - { - for(size_t i = 0; i < sz; ++i) - { - ary[i]=oth[i]; - } - return *this; - } - - array& operator=(array&& oth) - { - for(size_t i = 0; i < sz; ++i) - { - ary[i]=gp::move(oth[i]); - } - return *this; - } - constexpr T& operator[] (size_t off) { if constexpr (gp_config::has_buffer_bounds) diff --git a/include/gp/bloomfilter.hpp b/include/gp/bloomfilter.hpp index 2bd663e..21f1ef8 100644 --- a/include/gp/bloomfilter.hpp +++ b/include/gp/bloomfilter.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -17,7 +18,7 @@ namespace gp { uint32_t >::type, phys_size - > data{}; + > data; template static void set_bit(T* value, const int v_pos) { @@ -30,6 +31,11 @@ namespace gp { } public: + bloomfilter() + { + fill(data, 0); + } + void set_hash(hash_type v) { const size_t modulo = v & ((1 << magnitude)-1); diff --git a/include/gp/buffer.hpp b/include/gp/buffer.hpp index 6cbb2f2..beccefc 100644 --- a/include/gp/buffer.hpp +++ b/include/gp/buffer.hpp @@ -114,7 +114,7 @@ namespace gp{ { if(new_sz<=size()) { - return buffer{&*(end()-(1+new_sz)), &*end()}; + return buffer{&*(end()-(new_sz)), &*end()}; } else { diff --git a/include/gp/enveloppe/cbor.hpp b/include/gp/enveloppe/cbor.hpp index 10c7ccc..65ab6d8 100644 --- a/include/gp/enveloppe/cbor.hpp +++ b/include/gp/enveloppe/cbor.hpp @@ -252,11 +252,12 @@ namespace gp { case cbor_composite::alt>(): { auto& ary = contents.value>(); auto it_begin = encode_length(dest, cbor_type::list, ary.size()); - if(it_begin != dest.begin()) return dest.begin(); + if(it_begin == dest.begin()) return dest.begin(); for(auto& elem : ary) { auto slice = dest.slice_end(dest.size() - (it_begin - dest.begin())); auto it = elem.encode(slice); - if(it == it_begin) return dest.begin(); + if(it == it_begin) + return dest.begin(); it_begin = it; } return it_begin; @@ -264,12 +265,14 @@ namespace gp { case cbor_composite::alt>>(): { auto& ary = contents.value>>(); auto it_begin = encode_length(dest, cbor_type::hmap, ary.size()); - if(it_begin != dest.begin()) return dest.begin(); + if(it_begin == dest.begin()) return dest.begin(); + for(auto& elem : ary) { auto slice = dest.slice_end(dest.size() - (it_begin - dest.begin())); auto it = elem.first.encode(slice); if(it == it_begin) return dest.begin(); it_begin = it; + slice = dest.slice_end(dest.size() - (it_begin - dest.begin())); it = elem.second.encode(slice); if(it == it_begin) return dest.begin(); @@ -285,6 +288,7 @@ namespace gp { case cbor_composite::alt(): { return encode_float(dest, contents.value()); } + default: return dest.begin(); } } }; diff --git a/include/gp/quotient_filter.hpp b/include/gp/quotient_filter.hpp index 08a22cf..fbbb0b8 100644 --- a/include/gp/quotient_filter.hpp +++ b/include/gp/quotient_filter.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -104,6 +105,10 @@ namespace gp { } public: + quotient_filter() { + gp::fill(data, node{0,0,0}); + } + void set_hash(hash_type v) { const size_t q = v & ((1 << magnitude)-1); diff --git a/tests/cbor_test.cpp b/tests/cbor_test.cpp index 414077d..5f40213 100644 --- a/tests/cbor_test.cpp +++ b/tests/cbor_test.cpp @@ -59,6 +59,72 @@ struct cbor_test : public test_scaffold { gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc})); gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc})); data = gen; + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b10100010), + std::byte(0b00001100), + std::byte(0b00111000), std::byte(98), + std::byte(0b00001101), + std::byte(0b00011000), std::byte(98) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } + { + gp::cbor_value data{alloc}; + data = gp::cbor_number(1); + + gp::array serialized; + gp::array serialized_manual{ + std::byte(1) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } + { + gp::cbor_value data{alloc}; + data = gp::cbor_floating_point(128.5f); + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b11111010), + std::byte(0b01000011), + std::byte(0b00000000), + std::byte(0b10000000), + std::byte(0b00000000) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } + { + gp::array str{'h', 'e', 'l', 'l', 'o'}; + gp::cbor_value data{alloc}; + data = str.as_buffer().cast(); + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b01000101), + std::byte('h'), + std::byte('e'), + std::byte('l'), + std::byte('l'), + std::byte('o') + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); } return 0;