Class AdjacencyListGraph

All Implemented Interfaces:
Iterable<Node>, Element, Graph, Structure, AttributeSink, ElementSink, Pipe, Replayable, Sink, Source
Direct Known Subclasses:
MultiGraph, SingleGraph

public class AdjacencyListGraph
extends AbstractGraph

A lightweight graph class intended to allow the construction of big graphs (millions of elements).

The main purpose here is to minimize memory consumption even if the management of such a graph implies more CPU consuming. See the complexity tags on each method so as to figure out the impact on the CPU.

  • Field Details

  • Constructor Details

    • AdjacencyListGraph

      public AdjacencyListGraph​(String id, boolean strictChecking, boolean autoCreate, int initialNodeCapacity, int initialEdgeCapacity)
      Creates an empty graph.
      Parameters:
      id - Unique identifier of the graph.
      strictChecking - If true any non-fatal error throws an exception.
      autoCreate - If true (and strict checking is false), nodes are automatically created when referenced when creating a edge, even if not yet inserted in the graph.
      initialNodeCapacity - Initial capacity of the node storage data structures. Use this if you know the approximate maximum number of nodes of the graph. The graph can grow beyond this limit, but storage reallocation is expensive operation.
      initialEdgeCapacity - Initial capacity of the edge storage data structures. Use this if you know the approximate maximum number of edges of the graph. The graph can grow beyond this limit, but storage reallocation is expensive operation.
    • AdjacencyListGraph

      public AdjacencyListGraph​(String id, boolean strictChecking, boolean autoCreate)
      Creates an empty graph with default edge and node capacity.
      Parameters:
      id - Unique identifier of the graph.
      strictChecking - If true any non-fatal error throws an exception.
      autoCreate - If true (and strict checking is false), nodes are automatically created when referenced when creating a edge, even if not yet inserted in the graph.
    • AdjacencyListGraph

      public AdjacencyListGraph​(String id)
      Creates an empty graph with strict checking and without auto-creation.
      Parameters:
      id - Unique identifier of the graph.
  • Method Details

    • nodes

      public Stream<Node> nodes()
    • edges

      public Stream<Edge> edges()
    • getEdge

      public Edge getEdge​(String id)
      Description copied from interface: Graph
      Get an edge by its identifier. This method is implicitly generic and returns something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

       ExtendedEdge edge = graph.getEdge("...");
       

      the method will return an ExtendedEdge edge. If no left part exists, method will just return an Edge.

      Parameters:
      id - Identifier of the edge to find.
      Returns:
      The searched edge or null if not found.
    • getEdge

      public Edge getEdge​(int index)
      Description copied from interface: Graph
      Get an edge by its index. This method is implicitly generic and returns something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :

       ExtendedEdge edge = graph.getEdge(index);
       

      the method will return an ExtendedEdge edge. If no left part exists, method will just return an Edge.

      Parameters:
      index - The index of the edge to find.
      Returns:
      The edge with the given index
    • getEdgeCount

      public int getEdgeCount()
      Description copied from interface: Structure
      Number of edges in this graph.
      Returns:
      The number of edges.
    • getNode

      public Node getNode​(String id)
      Description copied from interface: Graph
      Get a node by its identifier. This method is implicitly generic and returns something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :

       ExtendedNode node = graph.getNode("...");
       

      the method will return an ExtendedNode node. If no left part exists, method will just return a Node.

      Parameters:
      id - Identifier of the node to find.
      Returns:
      The searched node or null if not found.
    • getNode

      public Node getNode​(int index)
      Description copied from interface: Graph
      Get a node by its index. This method is implicitly generic and returns something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :

       ExtendedNode node = graph.getNode(index);
       

      the method will return an ExtendedNode node. If no left part exists, method will just return a Node.

      Parameters:
      index - Index of the node to find.
      Returns:
      The node with the given index
    • getNodeCount

      public int getNodeCount()
      Description copied from interface: Structure
      Number of nodes in this graph.
      Returns:
      The number of nodes.