Java 类org.apache.commons.collections15.buffer.UnboundedFifoBuffer 实例源码

项目:BfROpenLab    文件:WeakComponentClusterer.java   
/**
 * Extracts the weak components from a graph.
 * @param graph the graph whose weak components are to be extracted
 * @return the list of weak components
 */
public Set<Set<V>> transform(Graph<V,E> graph) {

    Set<Set<V>> clusterSet = new HashSet<Set<V>>();

    HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices());

    while (!unvisitedVertices.isEmpty()) {
        Set<V> cluster = new HashSet<V>();
        V root = unvisitedVertices.iterator().next();
        unvisitedVertices.remove(root);
        cluster.add(root);

        Buffer<V> queue = new UnboundedFifoBuffer<V>();
        queue.add(root);

        while (!queue.isEmpty()) {
            V currentVertex = queue.remove();
            Collection<V> neighbors = graph.getNeighbors(currentVertex);

            for(V neighbor : neighbors) {
                if (unvisitedVertices.contains(neighbor)) {
                    queue.add(neighbor);
                    unvisitedVertices.remove(neighbor);
                    cluster.add(neighbor);
                }
            }
        }
        clusterSet.add(cluster);
    }
    return clusterSet;
}
项目:ODL    文件:WeakComponentClusterer.java   
/**
 * Extracts the weak components from a graph.
 * @param graph the graph whose weak components are to be extracted
 * @return the list of weak components
 */
public Set<Set<V>> transform(Graph<V,E> graph) {

    Set<Set<V>> clusterSet = new HashSet<Set<V>>();

    HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices());

    while (!unvisitedVertices.isEmpty()) {
        Set<V> cluster = new HashSet<V>();
        V root = unvisitedVertices.iterator().next();
        unvisitedVertices.remove(root);
        cluster.add(root);

        Buffer<V> queue = new UnboundedFifoBuffer<V>();
        queue.add(root);

        while (!queue.isEmpty()) {
            V currentVertex = queue.remove();
            Collection<V> neighbors = graph.getNeighbors(currentVertex);

            for(V neighbor : neighbors) {
                if (unvisitedVertices.contains(neighbor)) {
                    queue.add(neighbor);
                    unvisitedVertices.remove(neighbor);
                    cluster.add(neighbor);
                }
            }
        }
        clusterSet.add(cluster);
    }
    return clusterSet;
}