Ejemplo n.º 1
0
  /**
   * Returns a set of all vertices that are in the maximally connected component together with the
   * specified vertex. For more on maximally connected component, see <a
   * href="http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html">
   * http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html</a>.
   *
   * @param vertex the vertex for which the connected set to be returned.
   * @return a set of all vertices that are in the maximally connected component together with the
   *     specified vertex.
   */
  public Set connectedSetOf(Object vertex) {
    Set connectedSet = (Set) m_vertexToConnectedSet.get(vertex);

    if (connectedSet == null) {
      connectedSet = new HashSet();

      BreadthFirstIterator i = new BreadthFirstIterator(m_graph, vertex);

      while (i.hasNext()) {
        connectedSet.add(i.next());
      }

      m_vertexToConnectedSet.put(vertex, connectedSet);
    }

    return connectedSet;
  }
Ejemplo n.º 2
0
  private List lazyFindConnectedSets() {
    if (m_connectedSets == null) {
      m_connectedSets = new ArrayList();

      Set vertexSet = m_graph.vertexSet();

      if (vertexSet.size() > 0) {
        BreadthFirstIterator i = new BreadthFirstIterator(m_graph, null);
        i.addTraversalListener(new MyTraversalListener());

        while (i.hasNext()) {
          i.next();
        }
      }
    }

    return m_connectedSets;
  }