public class DynamicGraph<T> extends Object implements ObjectGraph<T>
| Constructor and Description |
|---|
DynamicGraph()
Create a graph with the default initial capacity of 128.
|
DynamicGraph(int targetSize)
Create a graph with the passed initial capacity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(T depender,
T dependee)
Ad an edge from one node to another.
|
List<Score<T>> |
apply(RankingAlgorithm<?> alg) |
Set<T> |
bottomLevelNodes()
Get the set of nodes which have no outbound edges.
|
List<T> |
byClosureSize()
Get a list of the nodes in the graph sorted by the size of their closure.
|
List<T> |
byReverseClosureSize()
Get a list of the nodes in the graph sorted by the size of their reverse
closure (all paths to the top of the graph from this node).
|
Set<T> |
children(T node)
Get the set of string node names which are immediate child nodes of a
given one (if the graph is cyclic, this may include the node name
passed).
|
void |
clear()
Clear the contents of the graph.
|
Set<T> |
closureOf(T node)
Get the closure of this node in the graph - all nodes which are reachable
following outbound edges from this node and its descendants.
|
int |
closureSize(T node)
Determine the size of the closure of this node, following outbound edges
to the bottom of the graph, traversing each node once.
|
boolean |
contains(T item)
Determine if this graph contains the item passed.
|
Set<T> |
disjunctionOfClosureOfHighestRankedNodes()
This requires some explaining - it is used to pick the initial set of
colorings that are active - attempting to find nodes that are likely to
be ones someone would want flagged.
|
int |
distance(T a,
T b)
Get the distance along the shortest path between two node.
|
Set<String> |
edgeStrings()
For logging convenience, get a list of strings that identify the edges
present in this graph.
|
List<Score<T>> |
eigenvectorCentrality()
Compute the eigenvector centrality - "most likely to be connected
*through*" - score for each node.
|
boolean |
equals(Object obj) |
boolean |
hasEdge(T depender,
T dependee)
Determine if an outbound edge is present from depender to dependee.
|
int |
hashCode() |
int |
inboundReferenceCount(T node)
Count the number of nodes that have outbound edges to the passed node.
|
boolean |
isUnreferenced(T node)
Returns true if this node has no inbound edges.
|
static <C extends WritableByteChannel & SeekableByteChannel,T> |
load(C channel,
IOFunction<ByteBuffer,T> func)
Load a graph from a FileChannel or similar.
|
ObjectGraph<T> |
omitting(Set<T> items)
Create a copy of this graph, omitting the passed set of
items.
|
int |
outboundReferenceCount(T node)
Count the number of nodes this node has outbound edges to.
|
List<Score<T>> |
pageRank()
Compute the pagerank score of every node in the graph.
|
Set<T> |
parents(T node)
Get the set of strings which are immediate parent nodes to a given one
(if the graph is cyclic, this may include the node name passed).
|
List<ObjectPath<T>> |
pathsBetween(T a,
T b)
Get the set of paths that exist between two nodes.
|
static BitSet |
readBitSet(ByteBuffer buffer,
int limit) |
boolean |
removeAllReferencesTo(T item)
Remove an item and all edges connected to it from the graph.
|
boolean |
removeEdge(T depender,
T dependee)
Remove an edge between two items.
|
Set<T> |
reverseClosureOf(T node)
Get the reverse closure of a node in the graph - all nodes which have an
outbound edge to this node, and all nodes which have an outbound edge to
one of those, and so forth, to the top of the graph.
|
int |
reverseClosureSize(T node)
Determine the size of the inverse closure of this node, following inbound
edges to the top of the graph, traversing each node once.
|
int |
revision()
Get the number of changes that have been made to this graph since its
creation; typically used to determine if the graph has changed since some
computation was performed.
|
void |
save(ObjectOutput out)
Optimized serialization support.
|
boolean |
setOutboundEdges(T item,
Set<T> dependencies)
Set the outbound edges from an item, removing any edges that previously
existed which are not present in the passed set.
|
int |
size()
Returns the number of items belonging to this graph.
|
<C extends WritableByteChannel & SeekableByteChannel> |
store(C channel,
IOToIntBiFunction<T,C> itemWriter)
Store this graph to a FileChannel or similar.
|
void |
toIntGraph(BiConsumer<IndexedResolvable<? extends T>,IntGraph> consumer)
Convert this graph to its (usually internal) IntGraph, needed for
serialization.
|
T |
toNode(int index)
Get the node for an index.
|
int |
toNodeId(T name)
Get the integer id used internally for a node.
|
Set<T> |
topLevelOrOrphanNodes()
Get the set of nodes which have no inbound edges.
|
String |
toString() |
void |
walk(ObjectGraphVisitor<? super T> v)
Walk the tree of nodes in some order, such that each node is only visited
once.
|
void |
walk(T startingWith,
ObjectGraphVisitor<? super T> v)
Walk the tree of node definitions and node references in some order,
starting from the passed starting node.
|
void |
walkUpwards(T startingWith,
ObjectGraphVisitor<? super T> v)
Walk the antecedents of a node.
|
static <C extends WritableByteChannel & SeekableByteChannel> |
writeBitSet(BitSet set,
C channel,
ByteBuffer numBuffer) |
public DynamicGraph()
public DynamicGraph(int targetSize)
targetSize - public void toIntGraph(BiConsumer<IndexedResolvable<? extends T>,IntGraph> consumer)
ObjectGraphtoIntGraph in interface ObjectGraph<T>consumer - A consumer that takes the list of items and the
graph.public ObjectGraph<T> omitting(Set<T> items)
ObjectGraphomitting in interface ObjectGraph<T>items - The items to omitpublic int size()
size in interface ObjectGraph<T>public boolean contains(T item)
item - The itempublic int revision()
public void clear()
public boolean setOutboundEdges(T item, Set<T> dependencies)
item - dependencies - public boolean addEdge(T depender, T dependee)
depender - The first itemdependee - The second itempublic boolean removeAllReferencesTo(T item)
item - An itempublic boolean removeEdge(T depender, T dependee)
depender - The item with the outbound edgedependee - The item with the inbound edgepublic boolean hasEdge(T depender, T dependee)
depender - One nodedependee - Another nodepublic List<T> byClosureSize()
ObjectGraphbyClosureSize in interface ObjectGraph<T>public List<T> byReverseClosureSize()
ObjectGraphbyReverseClosureSize in interface ObjectGraph<T>public Set<String> edgeStrings()
ObjectGraphedgeStrings in interface ObjectGraph<T>public Set<T> parents(T node)
ObjectGraphparents in interface ObjectGraph<T>node - A node namepublic Set<T> children(T node)
ObjectGraphchildren in interface ObjectGraph<T>node - The node namepublic int inboundReferenceCount(T node)
ObjectGraphinboundReferenceCount in interface ObjectGraph<T>node - The node namepublic int outboundReferenceCount(T node)
ObjectGraphoutboundReferenceCount in interface ObjectGraph<T>node - The node namepublic Set<T> topLevelOrOrphanNodes()
ObjectGraphtopLevelOrOrphanNodes in interface ObjectGraph<T>public Set<T> bottomLevelNodes()
ObjectGraphbottomLevelNodes in interface ObjectGraph<T>public boolean isUnreferenced(T node)
ObjectGraphisUnreferenced in interface ObjectGraph<T>node - A nodepublic int closureSize(T node)
ObjectGraphclosureSize in interface ObjectGraph<T>node - A nodepublic int reverseClosureSize(T node)
ObjectGraphreverseClosureSize in interface ObjectGraph<T>public Set<T> reverseClosureOf(T node)
ObjectGraphreverseClosureOf in interface ObjectGraph<T>node - A node namepublic Set<T> closureOf(T node)
ObjectGraphclosureOf in interface ObjectGraph<T>node - A node namepublic void walk(ObjectGraphVisitor<? super T> v)
ObjectGraphwalk in interface ObjectGraph<T>v - A visitorpublic void walk(T startingWith, ObjectGraphVisitor<? super T> v)
ObjectGraphwalk in interface ObjectGraph<T>startingWith - The starting nodev - A visitorpublic void walkUpwards(T startingWith, ObjectGraphVisitor<? super T> v)
ObjectGraphwalkUpwards in interface ObjectGraph<T>startingWith - The starting nodev - A visitorpublic int distance(T a, T b)
ObjectGraphdistance in interface ObjectGraph<T>a - One nodeb - Another nodepublic List<Score<T>> eigenvectorCentrality()
ObjectGrapheigenvectorCentrality in interface ObjectGraph<T>public List<Score<T>> pageRank()
ObjectGraphpageRank in interface ObjectGraph<T>public Set<T> disjunctionOfClosureOfHighestRankedNodes()
ObjectGraphdisjunctionOfClosureOfHighestRankedNodes in interface ObjectGraph<T>public void save(ObjectOutput out) throws IOException
ObjectGraphsave in interface ObjectGraph<T>out - The outputIOException - If something goes wrongpublic int toNodeId(T name)
ObjectGraphtoNodeId in interface ObjectGraph<T>name - A nodepublic T toNode(int index)
ObjectGraphtoNode in interface ObjectGraph<T>index - The indexpublic List<Score<T>> apply(RankingAlgorithm<?> alg)
apply in interface ObjectGraph<T>public List<ObjectPath<T>> pathsBetween(T a, T b)
ObjectGraphpathsBetween in interface ObjectGraph<T>a - A first nodeb - A second nodepublic static <C extends WritableByteChannel & SeekableByteChannel,T> DynamicGraph<T> load(C channel, IOFunction<ByteBuffer,T> func) throws IOException
C - The channel typeT - The item typechannel - The channelfunc - A function which can read one element of type T from
a ByteBuffer, leaving it positioned at the first byte subsequent to
the itemIOException - If something goes wrongpublic <C extends WritableByteChannel & SeekableByteChannel> void store(C channel, IOToIntBiFunction<T,C> itemWriter) throws IOException
C - The channel typechannel - The channelitemWriter - A function which can write one item of type T to
a channel, leaving the channel's position immediately after the last
byte written, and returning the exact number of bytes the function
wrote (typical is to serialize the item to a byte array, write the
length and then the item bytes)IOException - If something goes wrongpublic static BitSet readBitSet(ByteBuffer buffer, int limit) throws IOException
IOExceptionpublic static <C extends WritableByteChannel & SeekableByteChannel> int writeBitSet(BitSet set, C channel, ByteBuffer numBuffer) throws IOException
IOExceptionCopyright © 2010–2019 Mastfrog Technologies. All rights reserved.