0.3.0
Loading...
Searching...
No Matches
Vector.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <vector>
17#include <span>
18
19namespace NAV
20{
21
26template<typename T>
27void move(std::vector<T>& v, size_t sourceIdx, size_t targetIdx)
28{
29 if (sourceIdx > targetIdx)
30 {
31 std::rotate(v.rend() - static_cast<int64_t>(sourceIdx) - 1,
32 v.rend() - static_cast<int64_t>(sourceIdx), v.rend() - static_cast<int64_t>(targetIdx));
33 }
34 else
35 {
36 std::rotate(v.begin() + static_cast<int64_t>(sourceIdx),
37 v.begin() + static_cast<int64_t>(sourceIdx) + 1, v.begin() + static_cast<int64_t>(targetIdx) + 1);
38 }
39}
40
45template<typename Scalar>
46std::vector<Scalar> genRangeVector(Scalar start, Scalar stepSize, Scalar end)
47{
48 std::vector<Scalar> container;
49 container.reserve(static_cast<size_t>(std::ceil((end - start) / stepSize)));
50
51 while (start < end)
52 {
53 container.push_back(start);
54 start += stepSize;
55 }
56
57 return container;
58};
59
64template<typename T>
65[[nodiscard]] bool operator==(const std::vector<T>& lhs, std::span<const T> rhs)
66{
67 if (lhs.size() != rhs.size()) { return false; }
68 for (size_t i = 0; i < lhs.size(); i++)
69 {
70 if (lhs[i] != rhs[i]) { return false; }
71 }
72 return true;
73}
74
79template<typename T>
80[[nodiscard]] bool operator==(std::span<const T> lhs, const std::vector<T>& rhs)
81{
82 return rhs == lhs;
83}
84
85} // namespace NAV
constexpr bool operator==(const Node::Kind &lhs, const Node::Kind &rhs)
Equal compares Node::Kind values.
Definition Node.hpp:494
std::vector< Scalar > genRangeVector(Scalar start, Scalar stepSize, Scalar end)
Returns a container filled with the given range.
Definition Vector.hpp:46
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.
Definition Vector.hpp:27