From 1596fcf349602f57dfdd9801c3e26cbc4aa02bee Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 17 Aug 2021 15:24:17 +0200 Subject: [PATCH] adt: rename optional table to optional array --- .../{optional_table.h => optional_array.h} | 28 +++++++++---------- lib/test/adt/CMakeLists.txt | 6 ++-- ...l_table_test.cc => optional_array_test.cc} | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-) rename lib/include/srsran/adt/{optional_table.h => optional_array.h} (83%) rename lib/test/adt/{optional_table_test.cc => optional_array_test.cc} (94%) diff --git a/lib/include/srsran/adt/optional_table.h b/lib/include/srsran/adt/optional_array.h similarity index 83% rename from lib/include/srsran/adt/optional_table.h rename to lib/include/srsran/adt/optional_array.h index 3f5a86ad4..f79efe6d8 100644 --- a/lib/include/srsran/adt/optional_table.h +++ b/lib/include/srsran/adt/optional_array.h @@ -10,8 +10,8 @@ * */ -#ifndef SRSRAN_OPTIONAL_TABLE_H -#define SRSRAN_OPTIONAL_TABLE_H +#ifndef SRSRAN_OPTIONAL_ARRAY_H +#define SRSRAN_OPTIONAL_ARRAY_H #include "optional.h" #include "srsran/common/srsran_assert.h" @@ -27,7 +27,7 @@ namespace srsran { * @tparam N static size of max nof items */ template -class optional_table +class optional_array { template class iterator_impl @@ -42,7 +42,7 @@ class optional_table using reference = Obj&; iterator_impl() = default; - iterator_impl(optional_table* parent_, size_t idx_) : parent(parent_), idx(idx_) + iterator_impl(optional_array* parent_, size_t idx_) : parent(parent_), idx(idx_) { if (idx < parent->capacity() and not parent->contains(idx)) { ++(*this); @@ -69,9 +69,9 @@ class optional_table bool operator!=(const It& other) const { return not(*this == other); } protected: - friend class optional_table; + friend class optional_array; - optional_table* parent = nullptr; + optional_array* parent = nullptr; size_t idx = N; }; @@ -79,14 +79,14 @@ public: using iterator = iterator_impl; using const_iterator = iterator_impl; - optional_table() {} - optional_table(const optional_table&) = default; - optional_table(optional_table&& other) noexcept : vec(std::move(other.vec)), nof_elems(other.nof_elems) + optional_array() = default; + optional_array(const optional_array&) = default; + optional_array(optional_array&& other) noexcept : vec(std::move(other.vec)), nof_elems(other.nof_elems) { other.nof_elems = 0; } - optional_table& operator=(const optional_table&) = default; - optional_table& operator =(optional_table&& other) noexcept + optional_array& operator=(const optional_array&) = default; + optional_array& operator =(optional_array&& other) noexcept { vec = std::move(other.vec); nof_elems = other.nof_elems; @@ -95,12 +95,12 @@ public: } // Find first position that is empty - size_t find_first_empty() + size_t find_first_empty(size_t start_guess = 0) { if (nof_elems == capacity()) { return N; } - for (size_t i = 0; i < N; ++i) { + for (size_t i = start_guess; i < N; ++i) { if (not vec[i].has_value()) { return i; } @@ -150,4 +150,4 @@ private: } // namespace srsran -#endif // SRSRAN_OPTIONAL_TABLE_H +#endif // SRSRAN_OPTIONAL_ARRAY_H diff --git a/lib/test/adt/CMakeLists.txt b/lib/test/adt/CMakeLists.txt index 890a74d81..da32e2afc 100644 --- a/lib/test/adt/CMakeLists.txt +++ b/lib/test/adt/CMakeLists.txt @@ -62,6 +62,6 @@ add_executable(cached_alloc_test cached_alloc_test.cc) target_link_libraries(cached_alloc_test srsran_common) add_test(cached_alloc_test cached_alloc_test) -add_executable(optional_table_test optional_table_test.cc) -target_link_libraries(optional_table_test srsran_common) -add_test(optional_table_test optional_table_test) +add_executable(optional_array_test optional_array_test.cc) +target_link_libraries(optional_array_test srsran_common) +add_test(optional_array_test optional_array_test) diff --git a/lib/test/adt/optional_table_test.cc b/lib/test/adt/optional_array_test.cc similarity index 94% rename from lib/test/adt/optional_table_test.cc rename to lib/test/adt/optional_array_test.cc index 466ab1fb4..5ea36b980 100644 --- a/lib/test/adt/optional_table_test.cc +++ b/lib/test/adt/optional_array_test.cc @@ -10,14 +10,14 @@ * */ -#include "srsran/adt/optional_table.h" +#include "srsran/adt/optional_array.h" #include "srsran/common/test_common.h" namespace srsran { void test_slot_table() { - optional_table table1; + optional_array table1; TESTASSERT(table1.size() == 0 and table1.empty()); TESTASSERT(not table1.contains(0));