adt: rename optional table to optional array

master
Francisco Paisana 3 years ago
parent 8c24cfebd3
commit 1596fcf349

@ -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 <typename T, size_t N>
class optional_table
class optional_array
{
template <typename Obj>
class iterator_impl
@ -42,7 +42,7 @@ class optional_table
using reference = Obj&;
iterator_impl() = default;
iterator_impl(optional_table<T, N>* parent_, size_t idx_) : parent(parent_), idx(idx_)
iterator_impl(optional_array<T, N>* 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<T, N>;
friend class optional_array<T, N>;
optional_table<T, N>* parent = nullptr;
optional_array<T, N>* parent = nullptr;
size_t idx = N;
};
@ -79,14 +79,14 @@ public:
using iterator = iterator_impl<T>;
using const_iterator = iterator_impl<const T>;
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

@ -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)

@ -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<int, 5> table1;
optional_array<int, 5> table1;
TESTASSERT(table1.size() == 0 and table1.empty());
TESTASSERT(not table1.contains(0));
Loading…
Cancel
Save