Is there a Directed Acyclic Graph (DAG) data type in Java, and should I use it?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 04:43:19

I don't know if it can help but take a look at JGraphT.

Paŭlo Ebermann

As you can see if regarding the "related" questions, similar questions were already asked. And no, Java does not have a general-purpose graph/tree/DAG data type (if we don't count Swing's TreeModel).

Make your own one.


Here is an example (readonly) interface:

interface Node<N extends Node<N,E>, E extends Edge<N,E>> {
    public Set<E> outgoingEdges();
    public Set<E> ingoingEdges();
}

interface Edge<N extends Node<N,E>, E extends Edge<N,E>> {
    public E source();
    public E sink();
}

You would then have

interface LRU implements Node<LRU, Line> { ... }
interface Line implements Edge<LRU, Line> { ... }

(or classes instead).

retrodrone

For this particular problem. I've decided to use a LinkedListMultimap from Guava.

FWIW if someone wants a standard-libraries only solution, A map of sets or a map of other collections might do the job too, although not as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!