Package com.qfs.graph
Interface IDirectedGraph<K,V,E>
- Type Parameters:
K- the type of the keys for the verticesV- the type of the content for the verticesE- the type of the edgesEdge convention: a
nullvalue for an edge between two nodes is interpreted as the absence of edges between these two nodes.
- All Superinterfaces:
Map<K,V>
- All Known Subinterfaces:
IConcurrentDirectedGraph<K,,V, E> IDirectedMultiGraph<K,,V, E> IQueryStoreTree,ITree<K,V, E>
- All Known Implementing Classes:
ConcurrentDirectedGraph,DirectedGraph,DirectedMultiGraph,QueryStoreTree,Tree,UnmodifiableDirectedMultiGraph,UserStoreGraph
Represent a mutable directed graph.
- Author:
- ActiveViam
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a node to the graph.filterEdges(Predicate<E> filter) Creates a directed graph with the same vertices but only the edges selected by a filter.default voidforEachNode(BiConsumer<K, V> consumer) Retrieves the edge linking a node to another.getEdges()Retrieves the (unordered) list of all edges in the graph.getEdgesFrom(K from) Retrieves all edges starting from a node and returns them along with the node they reach.getEdgesTo(K to) A lot slower thangetEdgesFrom(Object)since edges are indexed by their from node.default Collection<Map.Entry<K,V>> getNodes()getReached(Set<K> included) Returns all the nodes that can be reached from at least one of the included nodes.getReachers(Set<K> included) Returns all the nodes that have at least one of their edges ending in a node included in the given set.Finds the node reachable from a given node and a given edge.booleanChecks the existence of an edge between two nodes.booleanChecks whether or not this graph has cycles.voidReplaces a key by another.voidremoveEdge(K from, K to) Removes the edge between two nodes.default VremoveNode(K key) Removes a node from the graph.Changes the edge between two nodes.default VMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
addNode
Adds a node to the graph. If a node already exists with the same key it is overridden and all edges are now connected to the new node.- Parameters:
key- the key of the node to addvalue- the value of the node to add
-
setNode
-
removeNode
Removes a node from the graph.- Returns:
- the value associated with the node
-
getNodes
-
forEachNode
-
setEdge
Changes the edge between two nodes.- Parameters:
from- the node from which the edge should startto- the node to which this edge should goedge- the new value for the edge, anullvalue will be interpreted as a removal of the previous edge (if any)- Returns:
- the previous edge between
fromandto
-
removeEdge
Removes the edge between two nodes.- Parameters:
from- the node from which this edge startsto- the node to which this edge goes
-
getEdge
Retrieves the edge linking a node to another.- Parameters:
from- the node from which this edge startsto- the node to which this edge goes- Returns:
nulliffromandtoare not linked by convention
-
getEdges
Collection<E> getEdges()Retrieves the (unordered) list of all edges in the graph.- Returns:
- a non
nullbut possibly empty collection of edges
-
getTo
Finds the node reachable from a given node and a given edge.If two
Object.equals(Object)edges connect K to different nodes A and B, A or B will be returned non deterministically.- Parameters:
from- the node from which the edge startsedge- the edge to use- Returns:
- the node to which
fromis connected via edge, ornullif there is no such edge starting fromfrom
-
getEdgesFrom
Retrieves all edges starting from a node and returns them along with the node they reach.If
fromis not contained in the graph, an empty map will be returned.- Parameters:
from- the node from which the edges start- Returns:
- the edges (and the vertices' keys) that leave
from
-
getEdgesTo
A lot slower thangetEdgesFrom(Object)since edges are indexed by their from node.- Parameters:
to- the node to which the edge go- Returns:
- the vertices' keys and the edges that reach
to
-
getReachers
Returns all the nodes that have at least one of their edges ending in a node included in the given set.- Parameters:
included- the nodes to be included- Returns:
- the set containing all nodes that can reach one of the included nodes by following edges multiple times, it includes all the given nodes
-
getReached
Returns all the nodes that can be reached from at least one of the included nodes.- Parameters:
included- the nodes to be included.- Returns:
- the set containing all nodes that can be reached from one of the included nodes by following edges multiple times
-
hasEdge
Checks the existence of an edge between two nodes.Convention: an edge exist if
getEdge(Object, Object)returns a nonnullvalue.- Parameters:
from- the node from which the edge should startto- the node to which this edge connects- Returns:
trueif there is an edge between the 2 nodes,falseotherwise
-
moveKey
Replaces a key by another.Moves the value and all edges from and to the previous key to the new key.
- Parameters:
from- the original valueto- the destination value
-
filterEdges
Creates a directed graph with the same vertices but only the edges selected by a filter.- Parameters:
filter- tells for each edge if it should be copied in the new graph or not- Returns:
- the new graph, it has less edges but the contained vertices and edges are the same objects than in the original graph
-
isAcyclic
boolean isAcyclic()Checks whether or not this graph has cycles.- Returns:
trueif the graph has no cycle (is acyclic),falseotherwise
-