From 547127a6b994723c2d1576a5686d85998c5073b5 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 19 Aug 2024 21:11:46 +0200 Subject: [PATCH] Remove arrayref unit test. --- ...able_numeric_array_multi_value_read_view.h | 1 + ...meric_weighted_set_multi_value_read_view.h | 1 + ...dable_string_array_multi_value_read_view.h | 1 + ...tring_weighted_set_multi_value_read_view.h | 1 + .../searchlib/attribute/posting_list_merger.h | 1 + vespalib/CMakeLists.txt | 1 - vespalib/src/tests/arrayref/CMakeLists.txt | 8 -- vespalib/src/tests/arrayref/arrayref_test.cpp | 83 ------------------- vespalib/src/vespa/vespalib/util/arrayref.h | 62 +------------- 9 files changed, 7 insertions(+), 152 deletions(-) delete mode 100644 vespalib/src/tests/arrayref/CMakeLists.txt delete mode 100644 vespalib/src/tests/arrayref/arrayref_test.cpp diff --git a/searchlib/src/vespa/searchlib/attribute/extendable_numeric_array_multi_value_read_view.h b/searchlib/src/vespa/searchlib/attribute/extendable_numeric_array_multi_value_read_view.h index 2b4f22a91de7..144547117541 100644 --- a/searchlib/src/vespa/searchlib/attribute/extendable_numeric_array_multi_value_read_view.h +++ b/searchlib/src/vespa/searchlib/attribute/extendable_numeric_array_multi_value_read_view.h @@ -3,6 +3,7 @@ #pragma once #include +#include namespace search::attribute { diff --git a/searchlib/src/vespa/searchlib/attribute/extendable_numeric_weighted_set_multi_value_read_view.h b/searchlib/src/vespa/searchlib/attribute/extendable_numeric_weighted_set_multi_value_read_view.h index 6bb1ddedb92d..9b9bde805e64 100644 --- a/searchlib/src/vespa/searchlib/attribute/extendable_numeric_weighted_set_multi_value_read_view.h +++ b/searchlib/src/vespa/searchlib/attribute/extendable_numeric_weighted_set_multi_value_read_view.h @@ -3,6 +3,7 @@ #pragma once #include +#include namespace search::attribute { diff --git a/searchlib/src/vespa/searchlib/attribute/extendable_string_array_multi_value_read_view.h b/searchlib/src/vespa/searchlib/attribute/extendable_string_array_multi_value_read_view.h index 9a1ec45b86f0..3a2222e1e9c8 100644 --- a/searchlib/src/vespa/searchlib/attribute/extendable_string_array_multi_value_read_view.h +++ b/searchlib/src/vespa/searchlib/attribute/extendable_string_array_multi_value_read_view.h @@ -4,6 +4,7 @@ #include #include +#include namespace search::attribute { diff --git a/searchlib/src/vespa/searchlib/attribute/extendable_string_weighted_set_multi_value_read_view.h b/searchlib/src/vespa/searchlib/attribute/extendable_string_weighted_set_multi_value_read_view.h index b5b24e4e663f..8c3331f7b86c 100644 --- a/searchlib/src/vespa/searchlib/attribute/extendable_string_weighted_set_multi_value_read_view.h +++ b/searchlib/src/vespa/searchlib/attribute/extendable_string_weighted_set_multi_value_read_view.h @@ -4,6 +4,7 @@ #include #include +#include namespace search::attribute { diff --git a/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h b/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h index 2943fdaecc68..b5412f9f1d63 100644 --- a/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h +++ b/searchlib/src/vespa/searchlib/attribute/posting_list_merger.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace search::attribute { diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt index 82b5907acfc0..87ca154ef22f 100644 --- a/vespalib/CMakeLists.txt +++ b/vespalib/CMakeLists.txt @@ -31,7 +31,6 @@ vespa_define_module( src/tests/approx src/tests/array src/tests/arrayqueue - src/tests/arrayref src/tests/assert src/tests/barrier src/tests/benchmark diff --git a/vespalib/src/tests/arrayref/CMakeLists.txt b/vespalib/src/tests/arrayref/CMakeLists.txt deleted file mode 100644 index 5f4f8ee48ddd..000000000000 --- a/vespalib/src/tests/arrayref/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_arrayref_test_app TEST - SOURCES - arrayref_test.cpp - DEPENDS - vespalib -) -vespa_add_test(NAME vespalib_arrayref_test_app COMMAND vespalib_arrayref_test_app) diff --git a/vespalib/src/tests/arrayref/arrayref_test.cpp b/vespalib/src/tests/arrayref/arrayref_test.cpp deleted file mode 100644 index 358725d7e1bc..000000000000 --- a/vespalib/src/tests/arrayref/arrayref_test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include -#include - -using namespace vespalib; - -#if VESPALIB_ARRAYREF_IS_STD_SPAN - -// Testing of std::span should be handled by upstream - -#else - -TEST("require that default constructors create references to empty arrays") { - ArrayRef array_ref; - ConstArrayRef const_ref; - EXPECT_EQUAL(array_ref.size(), 0u); - EXPECT_EQUAL(array_ref.begin(), array_ref.end()); - EXPECT_EQUAL(const_ref.size(), 0u); - EXPECT_EQUAL(const_ref.begin(), const_ref.end()); -} - -TEST("require that data can be referenced") { - std::vector data({1,2,3}); - ArrayRef array_ref(data); - ConstArrayRef const_ref(data); - EXPECT_EQUAL(array_ref.size(), 3u); - EXPECT_EQUAL(array_ref.end() - array_ref.begin(), 3); - EXPECT_EQUAL(array_ref[1], 2); - EXPECT_EQUAL(const_ref.size(), 3u); - EXPECT_EQUAL(const_ref.end() - const_ref.begin(), 3); - EXPECT_EQUAL(const_ref[2], 3); -} - -TEST("require that non-const array ref can be written to") { - std::vector data({1,2,3}); - ArrayRef array_ref(data); - array_ref[1] = 5; - EXPECT_EQUAL(data[1], 5); -} - -TEST("require that references can be constified") { - std::vector data({1,2,3}); - const ArrayRef array_ref(data); - ConstArrayRef const_ref(array_ref); - EXPECT_EQUAL(const_ref.size(), 3u); - EXPECT_EQUAL(const_ref.end() - const_ref.begin(), 3); - EXPECT_EQUAL(const_ref[2], 3); -} - -TEST("require that references can be unconstified") { - std::vector data({1,2,3}); - const ConstArrayRef const_ref(data); - ArrayRef array_ref = unconstify(const_ref); - EXPECT_EQUAL(array_ref.size(), 3u); - EXPECT_EQUAL(array_ref.end() - array_ref.begin(), 3); - EXPECT_EQUAL(array_ref[1], 2); - array_ref[1] = 5; - EXPECT_EQUAL(data[1], 5); -} - -TEST("require that std::array references can be constified") { - std::array data({1,2,3}); - const ArrayRef array_ref(data); - ConstArrayRef const_ref(array_ref); - EXPECT_EQUAL(const_ref.size(), 3u); - EXPECT_EQUAL(const_ref.end() - const_ref.begin(), 3); - EXPECT_EQUAL(const_ref[2], 3); -} - -TEST("require that references can be unconstified") { - std::array data({1,2,3}); - const ConstArrayRef const_ref(data); - ArrayRef array_ref = unconstify(const_ref); - EXPECT_EQUAL(array_ref.size(), 3u); - EXPECT_EQUAL(array_ref.end() - array_ref.begin(), 3); - EXPECT_EQUAL(array_ref[1], 2); - array_ref[1] = 5; - EXPECT_EQUAL(data[1], 5); -} -#endif - -TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vespalib/src/vespa/vespalib/util/arrayref.h b/vespalib/src/vespa/vespalib/util/arrayref.h index 859ee56beaa3..2b55aeee51c8 100644 --- a/vespalib/src/vespa/vespalib/util/arrayref.h +++ b/vespalib/src/vespa/vespalib/util/arrayref.h @@ -1,78 +1,20 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include -#include -#include #include namespace vespalib { -#define VESPALIB_ARRAYREF_IS_STD_SPAN 1 - -#if VESPALIB_ARRAYREF_IS_STD_SPAN - template using ArrayRef = std::span; template using ConstArrayRef = std::span; -#else -/** - * This is a simple wrapper class for a typed array with no memory ownership. - * It is similar to std::string_view - **/ -template -class ArrayRef { -public: - constexpr ArrayRef() noexcept : _v(nullptr), _sz(0) { } - constexpr ArrayRef(T * v, size_t sz) noexcept : _v(v), _sz(sz) { } - template> - ArrayRef(std::vector & v) noexcept : _v(v.data()), _sz(v.size()) { } - template - ArrayRef(std::array & v) noexcept : _v(v.data()), _sz(SZ) { } - T & operator [] (size_t i) noexcept { return _v[i]; } - const T & operator [] (size_t i) const noexcept { return _v[i]; } - T * data() noexcept { return _v; } - const T * data() const noexcept { return _v; } - [[nodiscard]] size_t size() const noexcept { return _sz; } - [[nodiscard]] bool empty() const noexcept { return _sz == 0; } - T *begin() noexcept { return _v; } - T *end() noexcept { return _v + _sz; } -private: - T * _v; - size_t _sz; -}; - -template -class ConstArrayRef { -public: - constexpr ConstArrayRef(const T *v, size_t sz) noexcept : _v(v), _sz(sz) { } - template> - ConstArrayRef(const std::vector & v) noexcept : _v(v.data()), _sz(v.size()) { } - template - ConstArrayRef(const std::array & v) noexcept : _v(v.data()), _sz(SZ) { } - ConstArrayRef(const ArrayRef & v) noexcept : _v(v.data()), _sz(v.size()) { } - constexpr ConstArrayRef() noexcept : _v(nullptr), _sz(0) {} - const T & operator [] (size_t i) const noexcept { return _v[i]; } - [[nodiscard]] size_t size() const noexcept { return _sz; } - [[nodiscard]] bool empty() const noexcept { return _sz == 0; } - const T *cbegin() const noexcept { return _v; } - const T *cend() const noexcept { return _v + _sz; } - const T *begin() const noexcept { return _v; } - const T *end() const noexcept { return _v + _sz; } - const T *data() const noexcept { return _v; } -private: - const T *_v; - size_t _sz; -}; -#endif - // const-cast for array references; use with care template -ArrayRef unconstify(const ConstArrayRef &ref) { - return ArrayRef(const_cast(ref.data()), ref.size()); +std::span unconstify(const std::span& ref) { + return std::span(const_cast(ref.data()), ref.size()); } }