inline bool parameters_equal(ContainerT const ¶meters, ContainerT const &new_parameters) { if (parameters.size() != new_parameters.size()) return false; // different parameter count typedef typename ContainerT::const_iterator const_iterator_type; const_iterator_type first1 = parameters.begin(); const_iterator_type last1 = parameters.end(); const_iterator_type first2 = new_parameters.begin(); const_iterator_type last2 = new_parameters.end(); while (first1 != last1 && first2 != last2) { // parameters are different, if the corresponding tokens are different using namespace boost::wave; if (token_id(*first1) != token_id(*first2) || (*first1).get_value() != (*first2).get_value()) { break; } ++first1; ++first2; } return (first1 == last1 && first2 == last2) ? true : false; }
void _copyData(const ContainerT& data, ResultT*& result) { if(data.size() == 0) { return; } result = new ResultT[data.size()]; std::copy(data.begin(), data.end(), result); }
inline void remove_placeholders (ContainerT &replacement_list) { using namespace boost::wave; // strip leading whitespace if (replacement_list.size() > 0) { typename ContainerT::iterator end = replacement_list.end(); typename ContainerT::iterator it = replacement_list.begin(); while (it != end) { if (T_PLACEHOLDER == token_id(*it)) { typename ContainerT::iterator next = it; ++next; replacement_list.erase(it); it = next; } else { ++it; } } // remove all 'new' leading and trailing whitespace trim_replacement_list(replacement_list); } }
template <class ContainerT> DynamicGraph(const NodeIterator nodes, const ContainerT &graph) { number_of_nodes = nodes; number_of_edges = (EdgeIterator)graph.size(); node_list.reserve(number_of_nodes + 1); node_list.resize(number_of_nodes + 1); EdgeIterator edge = 0; EdgeIterator position = 0; for (const auto node : osrm::irange(0u, number_of_nodes)) { EdgeIterator lastEdge = edge; while (edge < number_of_edges && graph[edge].source == node) { ++edge; } node_list[node].firstEdge = position; node_list[node].edges = edge - lastEdge; position += node_list[node].edges; } node_list.back().firstEdge = position; edge_list.reserve(static_cast<std::size_t>(edge_list.size() * 1.1)); edge_list.resize(position); edge = 0; for (const auto node : osrm::irange(0u, number_of_nodes)) { for (const auto i : osrm::irange(node_list[node].firstEdge, node_list[node].firstEdge + node_list[node].edges)) { edge_list[i].target = graph[edge].target; edge_list[i].data = graph[edge].data; ++edge; } } }
template <typename ContainerT> StaticGraph(const int nodes, const ContainerT &graph) { BOOST_ASSERT(std::is_sorted(const_cast<ContainerT &>(graph).begin(), const_cast<ContainerT &>(graph).end())); number_of_nodes = nodes; number_of_edges = static_cast<EdgeIterator>(graph.size()); node_array.resize(number_of_nodes + 1); EdgeIterator edge = 0; EdgeIterator position = 0; for (const auto node : irange(0u, number_of_nodes + 1)) { EdgeIterator last_edge = edge; while (edge < number_of_edges && graph[edge].source == node) { ++edge; } node_array[node].first_edge = position; //=edge position += edge - last_edge; // remove } edge_array.resize(position); //(edge) edge = 0; for (const auto node : irange(0u, number_of_nodes)) { EdgeIterator e = node_array[node + 1].first_edge; for (const auto i : irange(node_array[node].first_edge, e)) { edge_array[i].target = graph[edge].target; edge_array[i].data = graph[edge].data; edge++; } } }
inline void trim_replacement_list (ContainerT &replacement_list) { using namespace boost::wave; // strip leading whitespace if (replacement_list.size() > 0) { typename ContainerT::iterator end = replacement_list.end(); typename ContainerT::iterator it = replacement_list.begin(); while (it != end && IS_CATEGORY(*it, WhiteSpaceTokenType)) { if (T_PLACEHOLDER != token_id(*it)) { typename ContainerT::iterator next = it; ++next; replacement_list.erase(it); it = next; } else { ++it; } } } // strip trailing whitespace if (replacement_list.size() > 0) { typename ContainerT::reverse_iterator rend = replacement_list.rend(); typename ContainerT::reverse_iterator rit = replacement_list.rbegin(); while (rit != rend && IS_CATEGORY(*rit, WhiteSpaceTokenType)) ++rit; typename ContainerT::iterator end = replacement_list.end(); typename ContainerT::iterator it = rit.base(); while (it != end && IS_CATEGORY(*it, WhiteSpaceTokenType)) { if (T_PLACEHOLDER != token_id(*it)) { typename ContainerT::iterator next = it; ++next; replacement_list.erase(it); it = next; } else { ++it; } } } }
inline void trim_sequence_right (ContainerT &argument) { using namespace boost::wave; // strip trailing whitespace (should be only one token) if (argument.size() > 0 && IS_CATEGORY(argument.back(), WhiteSpaceTokenType)) { argument.pop_back(); } }
inline void trim_argument_left (ContainerT &argument) { using namespace boost::wave; // strip leading whitespace (should be only one token) if (argument.size() > 0 && IS_CATEGORY(argument.front(), WhiteSpaceTokenType)) { argument.pop_front(); } }
inline void selection_sort(ContainerT &container) noexcept { const size_t containerSize = container.size(); for (size_t i = 0; i < containerSize - 1; ++i) { size_t elemIndex = i; for (int j = i; j < containerSize; ++j) { if (container.at(elemIndex) > container.at(j)) { elemIndex = j; } } algorithm::swap(container.at(i), container.at(elemIndex)); } }
void push_front_test() { using namespace boost::spirit; const char* cp = "one,two,three"; const char* cp_first = cp; const char* cp_last = cp + test_impl::string_length(cp); const char* cp_i[] = {"one","two","three"};; int i; ContainerT c; typename ContainerT::const_iterator it; scanner<char const*> scan( cp_first, cp_last ); match<> hit; hit = list_p( (*alpha_p)[ push_front_a(c)] , ch_p(',') ).parse(scan); BOOST_CHECK(hit); BOOST_CHECK_EQUAL(scan.first, scan.last); BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3)); for (i=2, it = c.begin();i>=0 && it != c.end();--i, ++it) BOOST_CHECK_EQUAL( cp_i[i], *it); scan.first = cp; }
/** * Constructs a DynamicGraph from a list of edges sorted by source node id. */ template <class ContainerT> DynamicGraph(const NodeIterator nodes, const ContainerT &graph) { // we need to cast here because DeallocatingVector does not have a valid const iterator BOOST_ASSERT(std::is_sorted(const_cast<ContainerT&>(graph).begin(), const_cast<ContainerT&>(graph).end())); number_of_nodes = nodes; number_of_edges = static_cast<EdgeIterator>(graph.size()); node_array.resize(number_of_nodes + 1); EdgeIterator edge = 0; EdgeIterator position = 0; for (const auto node : osrm::irange(0u, number_of_nodes)) { EdgeIterator last_edge = edge; while (edge < number_of_edges && graph[edge].source == node) { ++edge; } node_array[node].first_edge = position; node_array[node].edges = edge - last_edge; position += node_array[node].edges; } node_array.back().first_edge = position; edge_list.reserve(static_cast<std::size_t>(edge_list.size() * 1.1)); edge_list.resize(position); edge = 0; for (const auto node : osrm::irange(0u, number_of_nodes)) { for (const auto i : osrm::irange(node_array[node].first_edge, node_array[node].first_edge + node_array[node].edges)) { edge_list[i].target = graph[edge].target; BOOST_ASSERT(edge_list[i].target < number_of_nodes); edge_list[i].data = graph[edge].data; ++edge; } } }
inline void insertion_sort_recursive(ContainerT &container) noexcept { detail::_insertion_sort_recursive(container, container.size() - 1, container.size() - 1);; }