Skip to content

Commit

Permalink
Merge pull request #32177 from vespa-engine/toregge/remove-arrayref-u…
Browse files Browse the repository at this point in the history
…nit-test

Remove arrayref unit test.
  • Loading branch information
baldersheim authored Aug 19, 2024
2 parents c3c8832 + 547127a commit 5e430ac
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <vespa/searchcommon/attribute/i_multi_value_read_view.h>
#include <vector>

namespace search::attribute {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <vespa/searchcommon/attribute/i_multi_value_read_view.h>
#include <vector>

namespace search::attribute {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <vespa/searchcommon/attribute/i_multi_value_read_view.h>
#include <vespa/vespalib/stllike/allocator.h>
#include <vector>

namespace search::attribute {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <vespa/searchcommon/attribute/i_multi_value_read_view.h>
#include <vespa/vespalib/stllike/allocator.h>
#include <vector>

namespace search::attribute {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vespa/vespalib/btree/btree_key_data.h>
#include <vespa/searchlib/common/bitvector.h>
#include <vespa/vespalib/util/arrayref.h>
#include <vector>

namespace search::attribute {

Expand Down
1 change: 0 additions & 1 deletion vespalib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions vespalib/src/tests/arrayref/CMakeLists.txt

This file was deleted.

83 changes: 0 additions & 83 deletions vespalib/src/tests/arrayref/arrayref_test.cpp

This file was deleted.

62 changes: 2 additions & 60 deletions vespalib/src/vespa/vespalib/util/arrayref.h
Original file line number Diff line number Diff line change
@@ -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 <cstddef>
#include <vector>
#include <array>
#include <span>

namespace vespalib {

#define VESPALIB_ARRAYREF_IS_STD_SPAN 1

#if VESPALIB_ARRAYREF_IS_STD_SPAN

template <typename T>
using ArrayRef = std::span<T>;

template <typename T>
using ConstArrayRef = std::span<const T>;

#else
/**
* This is a simple wrapper class for a typed array with no memory ownership.
* It is similar to std::string_view
**/
template <typename T>
class ArrayRef {
public:
constexpr ArrayRef() noexcept : _v(nullptr), _sz(0) { }
constexpr ArrayRef(T * v, size_t sz) noexcept : _v(v), _sz(sz) { }
template<typename A=std::allocator<T>>
ArrayRef(std::vector<T, A> & v) noexcept : _v(v.data()), _sz(v.size()) { }
template<size_t SZ>
ArrayRef(std::array<T, SZ> & 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 <typename T>
class ConstArrayRef {
public:
constexpr ConstArrayRef(const T *v, size_t sz) noexcept : _v(v), _sz(sz) { }
template<typename A=std::allocator<T>>
ConstArrayRef(const std::vector<T, A> & v) noexcept : _v(v.data()), _sz(v.size()) { }
template<size_t SZ>
ConstArrayRef(const std::array<T, SZ> & v) noexcept : _v(v.data()), _sz(SZ) { }
ConstArrayRef(const ArrayRef<T> & 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 <typename T>
ArrayRef<T> unconstify(const ConstArrayRef<T> &ref) {
return ArrayRef<T>(const_cast<T*>(ref.data()), ref.size());
std::span<T> unconstify(const std::span<const T>& ref) {
return std::span<T>(const_cast<T*>(ref.data()), ref.size());
}

}

0 comments on commit 5e430ac

Please sign in to comment.