summaryrefslogtreecommitdiffhomepage
path: root/src/search-result.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/search-result.cpp')
-rw-r--r--src/search-result.cpp79
1 files changed, 54 insertions, 25 deletions
diff --git a/src/search-result.cpp b/src/search-result.cpp
index ed9c5194..1afd09df 100644
--- a/src/search-result.cpp
+++ b/src/search-result.cpp
@@ -11,27 +11,11 @@ namespace floormat {
Pointer<path_search_result::node> path_search_result::_pool; // NOLINT
-path_search_result::path_search_result()
-{
- constexpr auto min_length = TILE_MAX_DIM*2;
- if (_pool)
- {
- auto ptr = move(_pool);
- fm_debug_assert(ptr->vec.empty());
- auto next = move(ptr->_next);
- _node = move(ptr);
- _pool = move(next);
- }
- else
- {
- _node = Pointer<node>{InPlaceInit};
- _node->vec.reserve(min_length);
- }
-}
+path_search_result::path_search_result() = default;
path_search_result::~path_search_result() noexcept
{
- if (_node && _node->vec.capacity() > 0) [[likely]]
+ if (_node && _node->vec.capacity() > 0)
{
_node->vec.clear();
_node->_next = move(_pool);
@@ -52,7 +36,7 @@ path_search_result& path_search_result::operator=(const path_search_result& x) n
{
fm_debug_assert(_node);
fm_debug_assert(!_node->_next);
- if (&x != this)
+ if (&x != this) [[likely]]
_node->vec = x._node->vec;
_cost = x._cost;
return *this;
@@ -79,11 +63,59 @@ path_search_result& path_search_result::operator=(path_search_result&& other) no
return *this;
}
-size_t path_search_result::size() const { return _node->vec.size(); }
-bool path_search_result::empty() const { return _node->vec.empty(); }
+void path_search_result::allocate_node()
+{
+ constexpr auto min_length = TILE_MAX_DIM*2;
+
+ if (_node)
+ return;
+
+ if (_pool)
+ {
+ auto ptr = move(_pool);
+ fm_debug_assert(ptr->vec.empty());
+ auto next = move(ptr->_next);
+ _node = move(ptr);
+ _pool = move(next);
+ }
+ else
+ {
+ _node = Pointer<node>{InPlaceInit};
+ _node->vec.reserve(min_length);
+ }
+}
+
+ArrayView<const point> path_search_result::path() const
+{
+ if (!_node)
+ return {};
+ return { _node->vec.data(), _node->vec.size() };
+}
+
+vector_wrapper<point, vector_wrapper_repr::ref> path_search_result::raw_path()
+{
+ if (!_node)
+ allocate_node();
+ return {_node->vec};
+}
+
+size_t path_search_result::size() const
+{
+ return _node ? _node->vec.size() : 0;
+}
+
+bool path_search_result::empty() const
+{
+ return !_node || _node->vec.empty();
+}
+
+path_search_result::operator bool() const
+{
+ return _node && !_node->vec.empty();
+}
+
path_search_result::node::node() noexcept = default;
float path_search_result::time() const { return _time; }
-
uint32_t path_search_result::cost() const { return _cost; }
void path_search_result::set_cost(uint32_t value) { _cost = value; }
void path_search_result::set_time(float time) { _time = time; }
@@ -91,8 +123,5 @@ bool path_search_result::is_found() const { return _found; }
void path_search_result::set_found(bool value) { _found = value; }
uint32_t path_search_result::distance() const { return _distance; }
void path_search_result::set_distance(uint32_t dist) { _distance = dist; }
-path_search_result::operator bool() const { return !_node->vec.empty(); }
-ArrayView<const point> path_search_result::path() const { fm_assert(_node); return {_node->vec.data(), _node->vec.size()}; }
-vector_wrapper<point, vector_wrapper_repr::ref> path_search_result::raw_path() { fm_assert(_node); return {_node->vec}; }
} // namespace floormat