typename std::enable_if<is_binary_node<T>(), bool>::type is_less(T const* a, T const* b) { if (is_less(a->first, b->first)) return true; if (is_less(b->first, a->first)) return false; return is_less(a->second, b->second); }
/* between: is x in (a,b) on circle? */ int id_is_between(chordID *x, chordID *a, chordID *b) { if (id_equals(a, b)) return !id_equals(x, a); /* x is only node not in (x,x) */ else if (is_less(a, b)) return is_less(a, x) && is_less(x, b); else return is_less(a, x) || is_less(x, b); }
static bool node_insert_at(struct rbtree_elem **root, struct rbtree_elem *node, struct rbtree_elem *new_node, rbtree_less_func *less) { bool inserted; inserted = false; while (!inserted) { ASSERT(node!=nil); if (less(node, new_node)) /*(node->high < lowIP)*/ { if (node->right == nil) { node->right = new_node; new_node->parent = node; inserted = true; } else { node = node->right; } } else { ASSERT(is_less(new_node, node)); if (node->left == nil) { node->left = new_node; new_node->parent = node; inserted = true; } else { node = node->left; } } } rb_insert(root, new_node) ; return true; }
bool is_less(Tuple_value const& a, Tuple_value const& b) { auto cmp = [](Value const& x, Value const& y) { return is_less(x, y); }; return std::lexicographical_compare(a.data, a.data + a.len, b.data, b.data + b.len, cmp); }
inline bool is_less(std::vector<T> const& a, std::vector<T> const& b) { auto cmp = [](T const& x, T const& y) { return is_less(x, y); }; return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), cmp); }
// FIXME: Use a visitor for values. Also, push this into // a header file somewhere. bool is_less(Value const& a, Value const& b) { if (a.kind() < b.kind()) return true; if (b.kind() < a.kind()) return false; switch (a.kind()) { case error_value: return false; case integer_value: return a.get_integer() < b.get_integer(); case function_value: { std::less<void const*> cmp; return cmp(a.get_function(), b.get_function()); } case reference_value: return is_less(*a.get_reference(), *b.get_reference()); case array_value: case tuple_value: // FIXME: Implement me! return false; } throw std::runtime_error("unhandled value"); }
// Two table types are equal if all of their key fields // are equal inline bool is_less(Table_type const* a, Table_type const* b) { // Compare the types. Type_seq const& a_types = a->field_types(); Type_seq const& b_types = b->field_types(); auto cmp_type = [](Type const* x, Type const* y) { return is_less(x, y); }; return std::lexicographical_compare(a_types.begin(), a_types.end(), b_types.begin(), b_types.end(), cmp_type); }
auto is_less_by_than(F f, const X& x) { return [f, x](const auto& y) { internal::trigger_static_asserts<internal::unary_function_tag, F, decltype(y)>(); return is_less(internal::invoke(f, y), x); }; }
inline bool lexicographical_compare( const Range1T& Arg1, const Range2T& Arg2) { return std::lexicographical_compare( begin(Arg1), end(Arg1), begin(Arg2), end(Arg2), is_less()); }
int main(int, char*[]) { std::vector<A> objects; objects.push_back(A(3)); objects.push_back(A(5)); objects.push_back(A(-1)); std::cout << is_less(objects[1], objects[2]); std::sort(objects.begin(), objects.end(), is_less); for (auto& a: objects) { std::cout << a.i() << " "; } std::cout << std::endl; }
street_view_graph::street_view_graph(std::string infile){ srand(time(NULL)); std::string line; std::ifstream myfile(infile.c_str()); if(myfile.is_open()){ myfile >> njunctions_; myfile >> nstreets_; myfile >> total_time_; myfile >> ncars_; myfile >> start_; garage_.resize(ncars_, car(total_time_)); graph_.resize(njunctions_); for(int i = 0; i < njunctions_; ++i){ graph_[i] = new std::vector<edge>(); } //who cares about coordinates? getline(myfile, line); // this corrects a bug: when you read the individual inputs first, it doesn't count as a line, so we have to throw away an additional one at the start for(int i = 0; i < njunctions_; ++i){ getline(myfile, line); } int directions; edge new_edge; for(int i = 0; i < nstreets_; ++i){ myfile >> new_edge.src_; myfile >> new_edge.dst_; myfile >> directions; myfile >> new_edge.time_; myfile >> new_edge.length_; //if directions 1 input once, if 2 input twice graph_[new_edge.src_]->push_back(new_edge); if(directions == 2){ int temp_src = new_edge.src_; new_edge.src_ = new_edge.dst_; new_edge.dst_ = temp_src; graph_[new_edge.src_]->push_back(new_edge); } } for(int i = 0; i < njunctions_; ++i){ std::sort(graph_[i]->begin(), graph_[i]->end(), is_less()); } myfile.close(); }
void insort(linktyp *lp, headtyp *hp, int (*is_less)(datatyp d1, datatyp d2)) /* Sätter in länken sorterad enligt is_less */ { linktyp *sp, *ep; newlink(&sp); *sp = *lp; infirst(sp, hp); ep = lastlink(hp); // if(ep == NULL) return; while ( is_less(lp->data, ep->data) ) ep = predlink(ep); insucc(lp, ep); elimlink(&sp); }
auto is_less_by_and_by(F f, G g) { return [f, g](const auto& x, const auto& y) { internal::trigger_static_asserts<internal::unary_function_tag, F, decltype(x)>(); internal::trigger_static_asserts<internal::unary_function_tag, G, decltype(y)>(); using FOut = std::decay_t<internal::invoke_result_t<F, decltype(x)>>; using GOut = std::decay_t<internal::invoke_result_t<G, decltype(y)>>; static_assert(std::is_same<FOut, GOut>::value, "Functions must return the same type."); return is_less(internal::invoke(f, x), internal::invoke(g, y)); }; }
bool operator()(Decl_expr const* a) { return is_less(a, cast<Decl_expr>(b));; }
inline bool lexicographical_compare( const Range1T& Arg1, const Range2T& Arg2) { return lexicographical_compare(Arg1, Arg2, is_less()); }
bool operator()(Function_type const* a) { return is_less(a, cast<Function_type>(b)); }
bool operator()(Array_type const* a) { return is_less(a, cast<Array_type>(b)); }
typename std::enable_if<is_unary_node<T>(), bool>::type is_less(T const* a, T const* b) { return is_less(a->first, b->first); }
// Two flow types are equal if each of their key types // are equal inline bool is_less(Flow_type const* a, Flow_type const* b) { return is_less(a->key_types(), b->key_types()); }
bool operator()(Integer_type const* a) { return is_less(a, cast<Integer_type>(b)); }
bool operator()(Block_type const* a) { return is_less(a, cast<Block_type>(b)); }
inline bool lexicographical_compare( const Range1T& Arg1, const Range2T& Arg2) { return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_less()); }
bool operator()(Record_type const* a) { return is_less(a, cast<Record_type>(b)); }
// network specific types bool operator()(Layout_type const* a) { return is_less(a, cast<Layout_type>(b)); }
bool operator()(Flow_type const* a) { return is_less(a, cast<Flow_type>(b)); }
bool operator()(Table_type const* a) { return is_less(a, cast<Table_type>(b)); }
inline bool is_less(Literal_expr const* a, Literal_expr const* b) { return is_less(a->value(), b->value()); }
inline bool is_less(Reference_type const* a, Reference_type const* b) { return is_less(a->first, b->first); }
bool operator()(T const* a, T const* b) const { return is_less(a, b); }
bool operator()(Literal_expr const* a) { return is_less(a, cast<Literal_expr>(b)); }