forked from lingeringsocket/jgrapht
-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add interface * Add interface * Update old implementations * Add EulerTourRMQLCAFinder and tests for all implementations * Fix bug with disconnected graphs. * Add more tests * Fix Java related issues * Add support for multiple roots * Add Heavy Path Decomposition * Add forest generator * Add performance tests * Small fixes * docs + opt-heavy-path * Update docs * Update heavy-path tests * Refactor heavy-path decomposition * Fix checkstyle errors * Fix checkstyle errors * Fix checkstyle errors * Update docs * Update docs * Merge branch 'master' of https://github.com/jgrapht/jgrapht into lca # Conflicts: # jgrapht-core/src/main/java/org/jgrapht/GraphTests.java # jgrapht-core/src/main/java/org/jgrapht/generate/BarabasiAlbertForestGenerator.java # jgrapht-core/src/test/java/org/jgrapht/generate/BarabasiAlbertForestGeneratorTest.java * Fix imports * Fix imports * Update docs + tests * Fix doc * Add docs and reorganize lca package * Refactor lca package * Fix broken javadoc * Update documentation of BinaryLifting * Rename interface to LowestCommonAncestorAlgorithm * Update method names * Small fixes + documentation update * Restore vanished tests
- Loading branch information
1 parent
8935a18
commit 048bf34
Showing
19 changed files
with
2,361 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
jgrapht-core/src/main/java/org/jgrapht/alg/interfaces/LowestCommonAncestorAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* (C) Copyright 2018-2018, by Alexandru Valeanu and Contributors. | ||
* | ||
* JGraphT : a free Java graph-theory library | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either | ||
* | ||
* (a) the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation, or (at your option) any | ||
* later version. | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* (b) the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation. | ||
*/ | ||
package org.jgrapht.alg.interfaces; | ||
|
||
import org.jgrapht.alg.util.Pair; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Algorithm to compute a <a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor">lowest common ancestor</a> | ||
* in a tree, forest or DAG. | ||
* | ||
* @param <V> vertex the graph vertex type | ||
* | ||
* @author Alexandru Valeanu | ||
*/ | ||
public interface LowestCommonAncestorAlgorithm<V> { | ||
|
||
/** | ||
* Return the LCA of a and b | ||
* | ||
* @param a the first element to find LCA for | ||
* @param b the other element to find the LCA for | ||
* | ||
* @return the LCA of a and b, or null if there is no LCA. | ||
*/ | ||
V getLCA(V a, V b); | ||
|
||
/** | ||
* Return a list of LCAs for a batch of queries | ||
* | ||
* @param queries a list of pairs of vertices | ||
* @return a list L of LCAs where L(i) is the LCA for pair queries(i) | ||
*/ | ||
default List<V> getBatchLCA(List<Pair<V, V>> queries){ | ||
return queries.stream().map(p -> getLCA(p.getFirst(), p.getSecond())).collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Return the computed set of LCAs of a and b | ||
* | ||
* @param a the first element to find LCA for | ||
* @param b the other element to find the LCA for | ||
* | ||
* @return the set LCAs of a and b, or empty set if there is no LCA computed. | ||
* @throws UnsupportedOperationException - if the operation is not supported by the implementing class | ||
*/ | ||
Set<V> getLCASet(V a, V b); | ||
|
||
/** | ||
* Return a list of computed sets of LCAs for a batch of queries | ||
* | ||
* @param queries a list of pairs of vertices | ||
* @return a list L of LCAs where L(i) is the computed set of LCAs for pair queries(i) | ||
*/ | ||
default List<Set<V>> getBatchLCASet(List<Pair<V, V>> queries){ | ||
return queries.stream().map(p -> getLCASet(p.getFirst(), p.getSecond())).collect(Collectors.toList()); | ||
} | ||
} |
Oops, something went wrong.