partial-ordering

Does casting pointers to integers define a total order on pointers?

荒凉一梦 提交于 2021-02-07 18:42:46
问题 (related to my previous question) In QT, the QMap documentation says: The key type of a QMap must provide operator<() specifying a total order . However, in qmap.h , they seem to use something similar to std::less to compare pointers: /* QMap uses qMapLessThanKey() to compare keys. The default implementation uses operator<(). For pointer types, qMapLessThanKey() casts the pointers to integers before it compares them, because operator<() is undefined on pointers that come from different memory

Does casting pointers to integers define a total order on pointers?

旧时模样 提交于 2021-02-07 18:42:28
问题 (related to my previous question) In QT, the QMap documentation says: The key type of a QMap must provide operator<() specifying a total order . However, in qmap.h , they seem to use something similar to std::less to compare pointers: /* QMap uses qMapLessThanKey() to compare keys. The default implementation uses operator<(). For pointer types, qMapLessThanKey() casts the pointers to integers before it compares them, because operator<() is undefined on pointers that come from different memory

What is the best way to sort a partially ordered list?

断了今生、忘了曾经 提交于 2020-01-10 19:33:59
问题 Probably best illustrated with a small example. Given the relations A < B < C A < P < Q Correct outputs would be ABCPQ or APQBC or APBCQ ... etc. In other words, any ordering is valid in which the given relationships hold. I am most interested in the solution that is easiest to implement, but the best O(n) in speed and time is interesting as well. 回答1: This is called topological sorting. The standard algorithm is to output a minimal element, then remove it and repeat until done. 回答2: Do

What is the best way to sort a partially ordered list?

给你一囗甜甜゛ 提交于 2020-01-10 19:33:32
问题 Probably best illustrated with a small example. Given the relations A < B < C A < P < Q Correct outputs would be ABCPQ or APQBC or APBCQ ... etc. In other words, any ordering is valid in which the given relationships hold. I am most interested in the solution that is easiest to implement, but the best O(n) in speed and time is interesting as well. 回答1: This is called topological sorting. The standard algorithm is to output a minimal element, then remove it and repeat until done. 回答2: Do

Partial Ordered Comparator to Total Ordered Comparator

£可爱£侵袭症+ 提交于 2020-01-05 08:54:14
问题 First of all: this is not a duplicate of the question Partial Ordered Comparator but rather builds on it. My goal is to sort a list of objects (e.g. [2, "a", 1]) in-place such that after sorting no two integers are out of order. For this, I used the implementation in this answer with the following partial ordering and got a IllegalArgumentException : java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:868) at java.util

Why C++ template accepting array is not more specialized than one accepting pointer (bis)?

徘徊边缘 提交于 2019-12-23 08:03:05
问题 In reference to this question, which has indeed the same title but for which I found an answer in the standard. I have continued to dig the subject and finaly find out an example code for which this answer does not apply. Let's consider this piece of code: template<class T> void func(T* buf); //template I template<size_t N> void func(char (&buf) [N]); //template II void g(char (&buf)[3]) { func(buf) //Error: ambiguous function call (Clang, GCC, ICC, MSVC) } According to the partial ordering

PartialOrdering, StrictWeakOrdering, TotalOrdering, what's the main difference in application

为君一笑 提交于 2019-12-19 09:18:26
问题 [SGI official document] Because of irreflexivity and transitivity, operator< always satisfies the definition of a partial ordering. The definition of a strict weak ordering is stricter, and the definition of a total ordering is stricter still. And I also read the definition of strict weak ordering in the document: StrictWeakOrdering The first three axioms, irreflexivity, antisymmetry, and transitivity, are the definition of a partial ordering; transitivity of equivalence is required by the

Topological Sorting using LINQ

允我心安 提交于 2019-12-17 18:50:58
问题 I have a list of items that have a partial order relation, i. e, the list can be considered a partially ordered set. I want to sort this list in the same way as in this question. As correctly answered there, this is known as topological sorting. There's a reasonably simple known algorithm to solve the problem. I want a LINQ-like implementation of it. I already tried to use OrderBy extension method, but I'm quite sure it's not able to make topological sorting. The problem is that the IComparer

How to produce the model for partial orders?

蹲街弑〆低调 提交于 2019-12-10 23:56:43
问题 I am trying to use Z3 to produce a model for a set of SAT assertions describing a partial order theory. I tried the subtype example in Z3 guide but it seems I cannot get a concrete model. Is there a way that Z3 can produce a model that describes the orders among elements and satisfies all assertions I made? For example, following are the constraints for "subtype". Is it possible that Z3 may produce a model like "int-type *<* real-type *<* complex-type *<* obj-type *<* root-type" and "string

How does `std::less` work?

风格不统一 提交于 2019-12-09 10:10:16
问题 Pointer relational operators do not define a total order (§ 5.9 of the C++11 standard): If two pointers p and q of the same type point to different objects that are not members of the same object or elements of the same array or to different functions, or if only one of them is null, the results of p<q , p>q , p<=q , and p>=q are unspecified. std::less documentation says: The partial specialization of std::less for any pointer type yields a total order, even if the built-in operator< does not