Partial ordered Comparator

后端 未结 6 1485
灰色年华
灰色年华 2020-12-18 22:35

How to implement java.util.Comparator that orders its elements according to a partial order relation?

For example given a partial order relation a

6条回答
  •  半阙折子戏
    2020-12-18 22:51

    If a < b and b < c implies a < c, then you have made a total ordering by using the hashCodes. Take a < d, d < c. The partial order says that b and d not necessarily are ordered. By introducing hashCodes you provide an ordering.

    Example: is-a-descendant-of(human, human).

    Adam (hash 42) < Moses (hash 17), Adam < Joe (hash 9)
    

    Implies

    Adam < Joe < Moses
    

    A negative example would be the same relation, but when time travel allows being your own descendant.

提交回复
热议问题