AIToolbox
A library that offers tools for AI problem solving.
|
Go to the documentation of this file. 1 #ifndef AI_TOOLBOX_UTILS_INDEX_MAP_HEADER_FILE
2 #define AI_TOOLBOX_UTILS_INDEX_MAP_HEADER_FILE
13 template <
typename IdsIterator,
typename Container>
34 currentId_(id), items_(&items) {}
50 return currentId_ == other.currentId_;
67 typename = std::enable_if_t<std::is_same_v<U, std::bidirectional_iterator_tag> ||
68 std::is_same_v<U, std::random_access_iterator_tag>>>
75 typename = std::enable_if_t<std::is_same_v<U, std::bidirectional_iterator_tag> ||
76 std::is_same_v<U, std::random_access_iterator_tag>>>
84 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
87 retval.currentId_ += diff;
91 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
97 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
100 retval.currentId_ -= diff;
104 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
110 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
112 return currentId_ - other.currentId_;
115 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
117 return currentId_ < other.currentId_;
120 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
122 return currentId_ > other.currentId_;
125 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
127 return !(currentId_ > other.currentId_ );
130 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
132 return !(currentId_ < other.currentId_ );
135 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
137 return (*items_)[*(currentId_ + diff)];
140 template <
typename U = iterator_category,
typename = std::enable_if_t<std::is_same_v<U, std::random_access_iterator_tag>>>
142 return (*items_)[*(currentId_ + diff)];
146 IdsIterator currentId_;
168 template <
typename IdsContainer,
typename Container>
177 static constexpr
bool OwnsIds = !std::is_pointer_v<IdsContainer>;
180 const std::remove_pointer_t<IdsContainer> &
204 template <
bool Tmp = OwnsIds, std::enable_if_t<Tmp,
int> = 0>
205 IndexMap(IdsContainer ids, Container & items) : ids_(std::move(ids)), items_(items) {}
225 template <
bool Tmp = OwnsIds, std::enable_if_t<!Tmp,
int> = 0>
226 IndexMap(IdsContainer ids, Container & items) : ids_(*ids), items_(items) {}
231 template <
bool Tmp = OwnsIds, std::enable_if_t<Tmp,
int> = 0>
233 std::sort(std::begin(ids_), std::end(ids_), [
this](
auto lhs,
auto rhs) {
234 return items_[lhs] < items_[rhs];
271 auto size()
const {
return ids_.size(); }
282 template <
class T,
class Container>
283 IndexMap(std::initializer_list<T> i, Container c) -> IndexMap<std::vector<T>, Container>;
286 template <
typename IdsContainer,
typename Container>
287 IndexMap(IdsContainer, Container &) -> IndexMap<IdsContainer, Container>;
292 template <
typename IdsContainer,
typename Container>
310 currentId_(start), currentSkipId_(0), ids_(ids), items_(items)
334 return (&(items_) == &(other.items_)) &&
335 (&(ids_) == &(other.ids_)) &&
336 (currentId_ == other.currentId_);
342 while (currentId_ < items_.size() &&
343 currentSkipId_ < ids_.size() &&
344 currentId_ == ids_[currentSkipId_])
352 typename IdsContainer::size_type currentSkipId_;
353 const IdsContainer & ids_;
375 template <
typename IdsContainer,
typename Container>
384 static constexpr
bool OwnsIds = !std::is_pointer_v<IdsContainer>;
387 const std::remove_pointer_t<IdsContainer> &
411 template <
bool Tmp = OwnsIds, std::enable_if_t<Tmp,
int> = 0>
412 IndexSkipMap(IdsContainer ids, Container & items) : ids_(std::move(ids)), items_(items) {}
432 template <
bool Tmp = OwnsIds, std::enable_if_t<!Tmp,
int> = 0>
433 IndexSkipMap(IdsContainer ids, Container & items) : ids_(*ids), items_(items) {}
468 auto size()
const {
return ids_.size(); }
479 template<
class T,
class Container>
480 IndexSkipMap(std::initializer_list<T> i, Container c) -> IndexSkipMap<std::vector<T>, Container>;
483 template <
typename IdsContainer,
typename Container>
484 IndexSkipMap(IdsContainer, Container &) -> IndexSkipMap<IdsContainer, Container>;