galois.objects.graph
Class ArrayIndexedTree<N extends GObject>

java.lang.Object
  extended by galois.objects.graph.ArrayIndexedTree<N>
Type Parameters:
N - type of the data contained in a node
All Implemented Interfaces:
GObject, Graph<N>, IndexedGraph<N>, Mappable<GNode<N>>

public final class ArrayIndexedTree<N extends GObject>
extends Object
implements IndexedGraph<N>

Implementation of the IndexedGraph interface.


Nested Class Summary
static class ArrayIndexedTree.Builder
          A ArrayIndexedTree builder, providing combinations of several features.
protected  class ArrayIndexedTree.IndexedTreeNode
           
 
Method Summary
 void access(byte flags)
          Accesses this object.
 boolean add(GNode<N> src)
          Adds a node to the graph.
 boolean add(GNode<N> src, byte flags)
          Adds a node to the graph.
 boolean addNeighbor(GNode<N> src, GNode<N> dst)
          Adds an edge between the two nodes.
 boolean addNeighbor(GNode<N> src, GNode<N> dst, byte flags)
          Adds an edge between the two nodes.
 boolean contains(GNode<N> src)
          Checks if a node is in the graph All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.
 boolean contains(GNode<N> src, byte flags)
          Checks if a node is in the graph
 GNode<N> createNode(N n)
          Creates a new node holding the indicated data.
 GNode<N> createNode(N n, byte flags)
          Creates a new node holding the indicated data.
 GNode<N> getNeighbor(GNode<N> node, int idx)
          Get a particular neighbor of a given node All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.
 GNode<N> getNeighbor(GNode<N> node, int idx, byte flags)
          Get a particular neighbor of a given node
 boolean hasNeighbor(GNode<N> src, GNode<N> dst)
          Checks if there is an edge between the two nodes in this graph.
 boolean hasNeighbor(GNode<N> src, GNode<N> dst, byte flags)
          Checks if there is an edge between the two nodes in this graph.
 int inNeighborsSize(GNode<N> src)
          Computes the number of in neighbors of the node, i.e., the number of different vertices that have an outgoing edge that ends at the indicated node.
 int inNeighborsSize(GNode<N> src, byte flags)
          Computes the number of in neighbors of the node, i.e., the number of different vertices that have an outgoing edge that ends at the indicated node.
 boolean isDirected()
          Tests if the current graph is directed.
<A1> void
map(Lambda2Void<GNode<N>,A1> body, A1 arg1)
          Applies a function to each element of this mappable instance serially.
<A1> void
map(Lambda2Void<GNode<N>,A1> body, A1 arg1, byte flags)
          Applies a function to each element of this mappable instance serially.
<A1,A2> void
map(Lambda3Void<GNode<N>,A1,A2> body, A1 arg1, A2 arg2)
          Applies a function to each element of this mappable instance serially.
<A1,A2> void
map(Lambda3Void<GNode<N>,A1,A2> body, A1 arg1, A2 arg2, byte flags)
          Applies a function to each element of this mappable instance serially.
 void map(LambdaVoid<GNode<N>> body)
          Applies a function to each element of this mappable instance serially.
 void map(LambdaVoid<GNode<N>> body, byte flags)
          Applies a function to each element of this mappable instance serially.
 void mapInNeighbors(GNode<N> src, LambdaVoid<GNode<N>> body)
          Applies the function passed as parameter to every in neighbor of the given node exactly once.
 void mapInNeighbors(GNode<N> src, LambdaVoid<GNode<N>> closure, byte flags)
          Applies the function passed as parameter to every in neighbor of the given node exactly once.
<A1> void
mapInternal(Lambda2Void<GNode<N>,A1> body, MapInternalContext ctx, A1 arg1)
          Applies a function to each element of this mappable instance concurrently.
<A1,A2> void
mapInternal(Lambda3Void<GNode<N>,A1,A2> body, MapInternalContext ctx, A1 arg1, A2 arg2)
          Applies a function to each element of this mappable instance concurrently.
 void mapInternal(LambdaVoid<GNode<N>> body, MapInternalContext ctx)
          Applies a function to each element of this mappable instance concurrently.
 void mapInternalDone()
          Signals to instance that concurrent iteration is complete.
 int outNeighborsSize(GNode<N> src)
          Computes the number of out neighbors of the node, i.e., the number of different vertices that have an incoming edge that starts at the indicated node.
 int outNeighborsSize(GNode<N> src, byte flags)
          Computes the number of out neighbors of the node, i.e., the number of different vertices that have an incoming edge that starts at the indicated node.
 boolean remove(GNode<N> src)
          Removes a node from the graph along with all its outgoing/incoming edges.
 boolean remove(GNode<N> src, byte flags)
          Removes a node from the graph along with all its outgoing/incoming edges.
 boolean removeNeighbor(GNode<N> src, GNode<N> dst)
          Removes the edge between the two nodes from this graph.
 boolean removeNeighbor(GNode<N> src, GNode<N> dst, byte flags)
          Removes the edge between the two nodes from this graph.
 boolean removeNeighbor(GNode<N> node, int idx)
          Remove a particular neighbor of a given node.
 boolean removeNeighbor(GNode<N> src, int idx, byte flags)
          Remove a particular neighbor of a given node.
 void setNeighbor(GNode<N> src, GNode<N> dst, int idx)
          Set a particular neighbor of a given node.
 void setNeighbor(GNode<N> src, GNode<N> dst, int idx, byte flags)
          Set a particular neighbor of a given node.
 int size()
          Returns the number of nodes in this graph.
 int size(byte flags)
          Returns the number of nodes in this graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createNode

public final GNode<N> createNode(N n)
Description copied from interface: Graph
Creates a new node holding the indicated data. The new node is not automatically added to the graph (use Graph.add(GNode, byte)),

Specified by:
createNode in interface Graph<N extends GObject>
Parameters:
n - data contained in the new node.
Returns:
the newly created node.

createNode

public GNode<N> createNode(N n,
                           byte flags)
Description copied from interface: Graph
Creates a new node holding the indicated data. The new node is not automatically added to the graph (use Graph.add(GNode, byte)),

Specified by:
createNode in interface Graph<N extends GObject>
Parameters:
n - data contained in the new node.
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
the newly created node.

add

public final boolean add(GNode<N> src)
Description copied from interface: Graph
Adds a node to the graph. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
add in interface Graph<N extends GObject>
Parameters:
src - node created by the current graph
Returns:
true if the node was not already in the graph

add

public boolean add(GNode<N> src,
                   byte flags)
Description copied from interface: Graph
Adds a node to the graph.

Specified by:
add in interface Graph<N extends GObject>
Parameters:
src - node created by the current graph
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the node was not already in the graph

remove

public final boolean remove(GNode<N> src)
Description copied from interface: Graph
Removes a node from the graph along with all its outgoing/incoming edges. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
remove in interface Graph<N extends GObject>
Parameters:
src - node to be removed
Returns:
true if the node was removed from the graph

remove

public boolean remove(GNode<N> src,
                      byte flags)
Description copied from interface: Graph
Removes a node from the graph along with all its outgoing/incoming edges.

Specified by:
remove in interface Graph<N extends GObject>
Parameters:
src - node to be removed
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the node was removed from the graph

contains

public final boolean contains(GNode<N> src)
Description copied from interface: Graph
Checks if a node is in the graph All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
contains in interface Graph<N extends GObject>
Parameters:
src - the node to check for
Returns:
true if the node is part of this graph

contains

public boolean contains(GNode<N> src,
                        byte flags)
Description copied from interface: Graph
Checks if a node is in the graph

Specified by:
contains in interface Graph<N extends GObject>
Parameters:
src - the node to check for
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the node is part of this graph

size

public final int size()
Description copied from interface: Graph
Returns the number of nodes in this graph. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
size in interface Graph<N extends GObject>
Returns:
the number of nodes (vertices) in this graph

size

public int size(byte flags)
Description copied from interface: Graph
Returns the number of nodes in this graph.

Specified by:
size in interface Graph<N extends GObject>
Parameters:
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
the number of nodes (vertices) in this graph

addNeighbor

public final boolean addNeighbor(GNode<N> src,
                                 GNode<N> dst)
Description copied from interface: Graph
Adds an edge between the two nodes. If the graph is directed, the first node is interpreted to be the source of the edge. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
addNeighbor in interface Graph<N extends GObject>
Parameters:
src - the source of the edge
dst - the destination of the edge
Returns:
true if the edge was not already in the graph

addNeighbor

public boolean addNeighbor(GNode<N> src,
                           GNode<N> dst,
                           byte flags)
Description copied from interface: Graph
Adds an edge between the two nodes. If the graph is directed, the first node is interpreted to be the source of the edge.

Specified by:
addNeighbor in interface Graph<N extends GObject>
Parameters:
src - the source of the edge
dst - the destination of the edge
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the edge was not already in the graph

removeNeighbor

public final boolean removeNeighbor(GNode<N> src,
                                    GNode<N> dst)
Description copied from interface: Graph
Removes the edge between the two nodes from this graph. If the graph is directed, the first node is interpreted to be the source of the edge. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
removeNeighbor in interface Graph<N extends GObject>
Parameters:
src - the source of the edge
dst - the target of the edge
Returns:
true if the edge was removed from this graph

removeNeighbor

public boolean removeNeighbor(GNode<N> src,
                              GNode<N> dst,
                              byte flags)
Description copied from interface: Graph
Removes the edge between the two nodes from this graph. If the graph is directed, the first node is interpreted to be the source of the edge.

Specified by:
removeNeighbor in interface Graph<N extends GObject>
Parameters:
src - the source of the edge
dst - the target of the edge
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the edge was removed from this graph

hasNeighbor

public final boolean hasNeighbor(GNode<N> src,
                                 GNode<N> dst)
Description copied from interface: Graph
Checks if there is an edge between the two nodes in this graph. If the graph is directed, the first node is interpreted to be the source of the edge. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
hasNeighbor in interface Graph<N extends GObject>
Parameters:
src - the source of the edge
dst - the target of the edge
Returns:
true if the two nodes are neighbors in this graph

hasNeighbor

public boolean hasNeighbor(GNode<N> src,
                           GNode<N> dst,
                           byte flags)
Description copied from interface: Graph
Checks if there is an edge between the two nodes in this graph. If the graph is directed, the first node is interpreted to be the source of the edge.

Specified by:
hasNeighbor in interface Graph<N extends GObject>
Parameters:
src - the source of the edge
dst - the target of the edge
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the two nodes are neighbors in this graph

mapInNeighbors

public final void mapInNeighbors(GNode<N> src,
                                 LambdaVoid<GNode<N>> body)
Description copied from interface: Graph
Applies the function passed as parameter to every in neighbor of the given node exactly once. For example, if we assume that each node contains an integer and we want to print the integer contained in each incoming neighbor of node in graph
   graph.mapInNeighbors(node, new LambdaVoid<GNode<Integer>>() {
      public void call(GNode<Integer> inNeighbor) {
        System.out.println(inNeighbor.getData());
     }
   }
 
If you wish to apply a function to the out neighbors, please use GNode#map All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
mapInNeighbors in interface Graph<N extends GObject>
Parameters:
src - a node in the graph
body - the function to be applied once to each incoming neighbor
See Also:
Mappable.map(util.fn.LambdaVoid)

mapInNeighbors

public void mapInNeighbors(GNode<N> src,
                           LambdaVoid<GNode<N>> closure,
                           byte flags)
Description copied from interface: Graph
Applies the function passed as parameter to every in neighbor of the given node exactly once. For example, if we assume that each node contains an integer and we want to print the integer contained in each incoming neighbor of node in graph
   graph.mapInNeighbors(node, new LambdaVoid<GNode<Integer>>() {
      public void call(GNode<Integer> inNeighbor) {
        System.out.println(inNeighbor.getData());
     }
   }
 
If you wish to apply a function to the out neighbors, please use GNode#map

Specified by:
mapInNeighbors in interface Graph<N extends GObject>
Parameters:
src - a node in the graph
closure - the function to be applied once to each incoming neighbor
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
See Also:
Mappable.map(util.fn.LambdaVoid)

inNeighborsSize

public final int inNeighborsSize(GNode<N> src)
Description copied from interface: Graph
Computes the number of in neighbors of the node, i.e., the number of different vertices that have an outgoing edge that ends at the indicated node. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
inNeighborsSize in interface Graph<N extends GObject>
Parameters:
src - a node in the graph
Returns:
the number of incoming neighbors

inNeighborsSize

public int inNeighborsSize(GNode<N> src,
                           byte flags)
Description copied from interface: Graph
Computes the number of in neighbors of the node, i.e., the number of different vertices that have an outgoing edge that ends at the indicated node.

Specified by:
inNeighborsSize in interface Graph<N extends GObject>
Parameters:
src - a node in the graph
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
the number of incoming neighbors

outNeighborsSize

public final int outNeighborsSize(GNode<N> src)
Description copied from interface: Graph
Computes the number of out neighbors of the node, i.e., the number of different vertices that have an incoming edge that starts at the indicated node. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
outNeighborsSize in interface Graph<N extends GObject>
Parameters:
src - a node in the graph
Returns:
the number of outgoing neighbors

outNeighborsSize

public int outNeighborsSize(GNode<N> src,
                            byte flags)
Description copied from interface: Graph
Computes the number of out neighbors of the node, i.e., the number of different vertices that have an incoming edge that starts at the indicated node.

Specified by:
outNeighborsSize in interface Graph<N extends GObject>
Parameters:
src - a node in the graph
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
the number of outgoing neighbors

isDirected

public boolean isDirected()
Description copied from interface: Graph
Tests if the current graph is directed.

Specified by:
isDirected in interface Graph<N extends GObject>
Returns:
true if the graph uses directed edges

setNeighbor

public final void setNeighbor(GNode<N> src,
                              GNode<N> dst,
                              int idx)
Description copied from interface: IndexedGraph
Set a particular neighbor of a given node. All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
setNeighbor in interface IndexedGraph<N extends GObject>
Parameters:
src - the node whose neighbor to set
dst - the new neighbor
idx - the particular neighbor to set

setNeighbor

public void setNeighbor(GNode<N> src,
                        GNode<N> dst,
                        int idx,
                        byte flags)
Description copied from interface: IndexedGraph
Set a particular neighbor of a given node.

Specified by:
setNeighbor in interface IndexedGraph<N extends GObject>
Parameters:
src - the node whose neighbor to set
dst - the new neighbor
idx - the particular neighbor to set
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag

getNeighbor

public final GNode<N> getNeighbor(GNode<N> node,
                                  int idx)
Description copied from interface: IndexedGraph
Get a particular neighbor of a given node All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
getNeighbor in interface IndexedGraph<N extends GObject>
Parameters:
node - the node whose neighbor to get
idx - the particular neighbor to get
Returns:
the neighbor at index

getNeighbor

public GNode<N> getNeighbor(GNode<N> node,
                            int idx,
                            byte flags)
Description copied from interface: IndexedGraph
Get a particular neighbor of a given node

Specified by:
getNeighbor in interface IndexedGraph<N extends GObject>
Parameters:
node - the node whose neighbor to get
idx - the particular neighbor to get
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
the neighbor at index

removeNeighbor

public final boolean removeNeighbor(GNode<N> node,
                                    int idx)
Description copied from interface: IndexedGraph
Remove a particular neighbor of a given node. Note that this is equivalent to calling setNeighbor(src, null, index) All the Galois runtime actions (e.g., conflict detection) will be performed when the method is executed.

Specified by:
removeNeighbor in interface IndexedGraph<N extends GObject>
Parameters:
node - the node whose neighbor to remove
idx - the neighbor to remove
Returns:
true if the neighbor was successfully removed

removeNeighbor

public boolean removeNeighbor(GNode<N> src,
                              int idx,
                              byte flags)
Description copied from interface: IndexedGraph
Remove a particular neighbor of a given node. Note that this is equivalent to calling setNeighbor(src, null, index)

Specified by:
removeNeighbor in interface IndexedGraph<N extends GObject>
Parameters:
src - the node whose neighbor to remove
idx - the neighbor to remove
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag
Returns:
true if the neighbor was successfully removed

mapInternal

public void mapInternal(LambdaVoid<GNode<N>> body,
                        MapInternalContext ctx)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance concurrently. Not intended to be called directly.

Specified by:
mapInternal in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
See Also:
GaloisRuntime.foreach(Mappable, LambdaVoid)

mapInternal

public <A1> void mapInternal(Lambda2Void<GNode<N>,A1> body,
                             MapInternalContext ctx,
                             A1 arg1)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance concurrently. Not intended to be called directly.

Specified by:
mapInternal in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
arg1 - additional argument to function
See Also:
GaloisRuntime.foreach(Mappable, Lambda2Void, Object)

mapInternal

public <A1,A2> void mapInternal(Lambda3Void<GNode<N>,A1,A2> body,
                                MapInternalContext ctx,
                                A1 arg1,
                                A2 arg2)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance concurrently. Not intended to be called directly.

Specified by:
mapInternal in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
arg1 - additional argument to function
arg2 - additional argument to function
See Also:
GaloisRuntime.foreach(Mappable, Lambda3Void, Object, Object)

map

public void map(LambdaVoid<GNode<N>> body)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance serially.

Specified by:
map in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element

map

public void map(LambdaVoid<GNode<N>> body,
                byte flags)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance serially.

Specified by:
map in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag

map

public <A1> void map(Lambda2Void<GNode<N>,A1> body,
                     A1 arg1)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance serially.

Specified by:
map in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
arg1 - additional argument to function

map

public <A1> void map(Lambda2Void<GNode<N>,A1> body,
                     A1 arg1,
                     byte flags)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance serially.

Specified by:
map in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
arg1 - argument to function
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag

map

public <A1,A2> void map(Lambda3Void<GNode<N>,A1,A2> body,
                        A1 arg1,
                        A2 arg2)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance serially.

Specified by:
map in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
arg1 - additional argument to function
arg2 - additional argument to function

map

public <A1,A2> void map(Lambda3Void<GNode<N>,A1,A2> body,
                        A1 arg1,
                        A2 arg2,
                        byte flags)
Description copied from interface: Mappable
Applies a function to each element of this mappable instance serially.

Specified by:
map in interface Mappable<GNode<N extends GObject>>
Parameters:
body - function to apply to each element
arg1 - additional argument to function
arg2 - additional argument to function
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag

mapInternalDone

public void mapInternalDone()
Description copied from interface: Mappable
Signals to instance that concurrent iteration is complete. Not intended to be called directly.

Specified by:
mapInternalDone in interface Mappable<GNode<N extends GObject>>

access

public void access(byte flags)
Description copied from interface: GObject
Accesses this object. Appropriate place to add hooks into the runtime system to implement conflict detection and rollback.

This method should be called before each access to a Galois object. Many implementing classes leave this implementation empty and instead implement conflict detection and rollback for each method of the object (e.g., GSet, Graph, etc), which is also known as "boosting".

Specified by:
access in interface GObject
Parameters:
flags - Galois runtime actions (e.g., conflict detection) that need to be executed upon invocation of this method. See MethodFlag