25#ifndef __BITPIT_COMMON_UTILS_TPP__
26#define __BITPIT_COMMON_UTILS_TPP__
53template <
typename T,
typename Comparator>
54bool addToOrderedVector(
const T &value, std::vector<T> &list, Comparator comparator)
57 list.push_back(value);
61 typename std::vector<T>::iterator itr = std::lower_bound(list.begin(), list.end(), value, comparator);
62 if (itr == list.end() || *itr != value) {
63 list.insert(itr, value);
89template <
typename T,
typename Comparator>
90typename std::vector<T>::const_iterator findInOrderedVector(
const T &value,
const std::vector<T> &list, Comparator comparator)
92 typename std::vector<T>::const_iterator itr = std::lower_bound(list.begin(), list.end(), value, comparator);
93 if (itr == list.end() || *itr != value) {
112void reorderVector(std::vector<size_t> &order, std::vector<T> &v, std::size_t size)
129template<
typename OrderContainer,
typename DataContainer>
132 for (std::size_t i = 0; i < size; i++) {
134 while (i != (j = order[i])) {
135 std::size_t k = order[j];
138 std::swap(order[i], order[j]);
154template<
typename Container,
typename Index>
157 std::swap(v[i], v[j]);
172 typename std::vector<T>::iterator it = find(vec.begin(), vec.end(), value);
173 if (it != vec.end()) {
190 std::vector<T> intersect;
191 std::map<T, bool> storage;
193 intersect.reserve(std::min(vec_1.size(), vec_2.size()));
194 for (
auto cit_ = vec_2.begin(); cit_ != vec_2.end(); ++cit_) {
195 storage[*cit_] =
true;
198 for (
auto it_ = vec_1.begin(); it_ != vec_1.end(); ++it_) {
200 intersect.push_back(*it_);
214 std::begin(std::declval<T&>()) != std::end(std::declval<T&>()),
215 ++std::declval<decltype(std::begin(std::declval<T&>()))&>(),
216 *std::begin(std::declval<T&>()),
224using is_iterable =
decltype(is_iterable_impl<T>(0));
void swapValue(std::vector< bool > &v, std::size_t i, std::size_t j)
std::vector< T > intersectionVector(const std::vector< T > &, const std::vector< T > &)
void reorderContainer(OrderContainer &order, DataContainer &v, std::size_t size)
auto is_iterable_impl(int) -> decltype(std::begin(std::declval< T & >()) !=std::end(std::declval< T & >()),++std::declval< decltype(std::begin(std::declval< T & >()))& >(), *std::begin(std::declval< T & >()), std::true_type{})
void reorderVector(std::vector< size_t > &order, std::vector< T > &v, std::size_t size)
void eraseValue(std::vector< T > &, const T &)