Class LowestCommonAncestorFinder<N,​E>


  • public class LowestCommonAncestorFinder<N,​E>
    extends java.lang.Object
    Implements a lowest common ancestor search algorithm.

    The LCA of a set of nodes is the node that is an ancestor to all of them but is not an ancestor of any other common ancestor. In a non-tree, There may be multiple LCAs for a given set of search nodes.

    In a cyclic graph, the LCAs may not be well defined. Within a cycle, all elements are both above and below one another, so there is no uniquely lowest element. If the set of common ancestors is rooted on a cycle, this implementation returns one or more elements of that cycle. Those elements are chosen arbitrarily but deterministically (as long as the underlying graph has deterministic iteration).

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  LowestCommonAncestorFinder.Factory<N,​E>
      An abstraction for LowestCommonAncestorFinder::new.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.common.collect.ImmutableSet<N> findAll​(java.util.Set<N> roots)
      Execute a search on all the elements of roots.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LowestCommonAncestorFinder

        public LowestCommonAncestorFinder​(DiGraph<N,​E> graph)
    • Method Detail

      • findAll

        public com.google.common.collect.ImmutableSet<N> findAll​(java.util.Set<N> roots)
        Execute a search on all the elements of roots.

        This is a general-purpose, bare-bones implementation. There are lots of special case optimizations that could be applied.