AIToolbox
A library that offers tools for AI problem solving.
|
Go to the documentation of this file. 1 #ifndef AI_TOOLBOX_UTILS_CORE_HEADER_FILE
2 #define AI_TOOLBOX_UTILS_CORE_HEADER_FILE
10 #include <boost/functional/hash.hpp>
30 inline unsigned ceil(
unsigned x,
unsigned y) {
31 return (x + y - 1) / y;
100 template <
typename V>
102 for (decltype(v.size()) i = 0; i < v.size(); ++i)
113 template <
typename V>
125 template <
typename V>
127 for (decltype(v.size()) i = 0; i < v.size(); ++i)
138 template <
typename V>
157 template <
typename V>
158 std::strong_ordering
veccmp(
const V & lhs,
const V & rhs) {
159 assert(lhs.size() == rhs.size());
160 for (decltype(lhs.size()) i = 0; i < lhs.size(); ++i) {
162 if (lhs[i] == rhs[i])
continue;
163 return lhs[i] > rhs[i] ? std::strong_ordering::greater : std::strong_ordering::less;
165 return std::strong_ordering::equal;
181 template <
typename V>
183 assert(lhs.size() == rhs.size());
184 for (decltype(lhs.size()) i = 0; i < lhs.size(); ++i) {
186 return lhs[i] <=> rhs[i];
188 return std::partial_ordering::equivalent;
204 template <
typename V>
206 assert(lhs.size() == rhs.size());
207 for (decltype(lhs.size()) i = 0; i < lhs.size(); ++i) {
209 return lhs[i] <=> rhs[i];
211 return std::partial_ordering::equivalent;
227 template <
typename It>
229 while (begin != end && *begin < elem) ++begin;
246 template <
typename It>
249 if (it != end && *it == elem)
return true;
265 template <
typename V>
267 assert(elems.size() <= v.size());
269 if (v.size() == elems.size())
270 return veccmp(v, elems) == 0;
272 decltype(v.size()) i = 0, j = 0;
273 while (j < elems.size()) {
274 while (i < v.size() && v[i] < elems[j]) ++i;
275 if (i == v.size() || v[i] > elems[j])
return false;
278 return j == elems.size();
287 template <
typename T>
289 const auto mid = lhs.size();
290 lhs.reserve(lhs.size() + rhs.size());
291 std::set_difference(std::begin(rhs), std::end(rhs),
292 std::begin(lhs), std::end(lhs), std::back_inserter(lhs));
293 std::inplace_merge(std::begin(lhs), std::begin(lhs)+mid, std::end(lhs));
315 template <
typename It,
typename F>
317 if (begin == end)
return std::make_pair(end, 0.0);
319 double max = std::invoke(unary_converter, *begin);
321 while (++begin != end) {
322 auto newV = std::invoke(unary_converter, *begin);
328 return std::make_pair(retval, max);
349 template <
typename T,
typename U>
350 void copyDumb3D(
const T & in, U & out,
const size_t d1,
const size_t d2,
const size_t d3) {
351 for (
size_t i = 0; i < d1; ++i )
352 for (
size_t j = 0; j < d2; ++j )
353 for (
size_t x = 0; x < d3; ++x )
354 out[i][j][x] = in[i][j][x];
363 return boost::hash_range(v.data(), v.data() + v.size());
size_t hash_value(const AIToolbox::Vector &v)
This function enables hashing of Vectors with boost::hash.
Definition: Core.hpp:362