Class Components<V>


  • public class Components<V>
    extends java.lang.Object
    • Constructor Detail

      • Components

        public Components​(V[] nodes)
      • Components

        public Components​(java.util.Collection<? extends java.util.Collection<V>> partition)
    • Method Detail

      • mergeComponentsOf

        public void mergeComponentsOf​(int indexA,
                                      int indexB)
        Merge the components of the two nodes. If they are in the same component, runs in O(1). If they are not, runs in O(n) (n = number of nodes).
        Parameters:
        indexA -
        indexB -
      • mergeComponentsOf

        public void mergeComponentsOf​(V nodeA,
                                      V nodeB)
        Merge the components of the two nodes. If they are in the same component, runs in O(1). If they are not, runs in O(n) (n = number of nodes). Use the integer variant if possible.
        Parameters:
        nodeA -
        nodeB -
      • mergeComponents

        public void mergeComponents​(int componentA,
                                    int componentB)
        Merge two components. The second component is kept.
        Parameters:
        componentA -
        componentB -
      • areInSameComponent

        public boolean areInSameComponent​(int nodeIndexA,
                                          int nodeIndexB)
      • areInSameComponent

        public boolean areInSameComponent​(V nodeA,
                                          V nodeB)
        Preferably use the integer variant.
        Parameters:
        nodeA -
        nodeB -
        Returns:
      • getComponentOf

        public int getComponentOf​(int node)
      • getComponentOf

        public int getComponentOf​(V node)
      • getNumberOfComponents

        public int getNumberOfComponents()
      • getComponents

        public java.util.List<java.util.Set<V>> getComponents()
      • getNodeIndicesOfComponent

        public java.lang.Iterable<java.lang.Integer> getNodeIndicesOfComponent​(int componentIndex)
      • normalise

        public int[] normalise()
        Put the components in increasing order 0...n
        Returns:
        The mapping from old component to new component.