001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.util;
014    
015    
016    /**
017     * An abstract interface for generic graphs; general graph utilities
018     * should be defined in terms of this interface and all graph
019     * implementations in the system should implement it.
020     *
021     *
022     * @see GraphNode
023     * @see GraphEdge
024     * @see GraphUtilities
025     */
026    public interface Graph {
027    
028      /**
029       * This method lists all of the nodes in a given graph.  This is
030       * defined in terms of generic GraphNodes.
031       *
032       * @see GraphNode
033       *
034       * @return an enumeration of all nodes in the graph
035       */
036      GraphNodeEnumeration enumerateNodes();
037    
038      /**
039       *  Find out how many nodes are in the graph
040       *
041       *  @return the number of nodes in the graph
042       */
043      int numberOfNodes();
044    
045      /**
046       *  After this method is called, all nodes in the graph should
047       * have a compact numbering from 0 to (number of nodes in
048       * graph - 1).  This number is what should be returned by
049       * {@link GraphNode#getIndex GraphNode.getIndex}.  This
050       * method is used by clients that want to e.g. allocate look-aside
051       * storage for graph nodes in an
052       * array.
053       */
054      void compactNodeNumbering();
055    
056      /**
057       *  Add a new graph node to the graph.
058       *
059       * @param node the node to add to the graph
060       */
061      void addGraphNode(GraphNode node);
062    
063      /**
064       *  Add a new edge to a graph.  This method is deliberately
065       * defined in terms of nodes to avoid requiring graphs that
066       * implement Graph have explicit edge objects.
067       *
068       * @param source the source node of the edge to add
069       * @param target the target node of the edge to add
070       */
071      void addGraphEdge(GraphNode source, GraphNode target);
072    }