Fixed size calculation in optimizeForestEdges()
This fixes the code in ConnGraph.optimizeForestEdges() that computes the resulting size after combining two Euler tour trees into one. Technically, the old behavior was still correct, but only by accident; this change is still kind of a bug fix.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.btrekkie.connectivity</groupId>
|
||||
<artifactId>dynamic-connectivity</artifactId>
|
||||
<version>0.1.2</version>
|
||||
<version>0.1.3</version>
|
||||
<name>dynamic-connectivity</name>
|
||||
<description>Data structure for dynamic connectivity in undirected graphs</description>
|
||||
<build>
|
||||
|
||||
@@ -1073,20 +1073,21 @@ public class ConnGraph {
|
||||
EulerTourVertex lowerVertex1 = vertex;
|
||||
EulerTourVertex lowerVertex2 = edge.vertex2;
|
||||
for (int lowerLevel = level - 1; lowerLevel > 0; lowerLevel--) {
|
||||
int size = 0;
|
||||
// Compute the total size if we combine the Euler tour trees
|
||||
int combinedSize = 1;
|
||||
if (lowerVertex1.lowerVertex != null) {
|
||||
size = lowerVertex1.lowerVertex.arbitraryVisit.root().size;
|
||||
combinedSize += lowerVertex1.lowerVertex.arbitraryVisit.root().size;
|
||||
} else {
|
||||
size = 1;
|
||||
combinedSize++;
|
||||
}
|
||||
if (lowerVertex2.lowerVertex != null) {
|
||||
size += lowerVertex2.lowerVertex.arbitraryVisit.root().size;
|
||||
combinedSize += lowerVertex2.lowerVertex.arbitraryVisit.root().size;
|
||||
} else {
|
||||
size++;
|
||||
combinedSize++;
|
||||
}
|
||||
|
||||
// X EulerTourVertices = (2 * X - 1) EulerTourNodes
|
||||
if (size > 2 * (1 << lowerLevel) - 1) {
|
||||
if (combinedSize > 2 * (1 << lowerLevel) - 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
target/dynamic-connectivity-0.1.3.jar
Normal file
BIN
target/dynamic-connectivity-0.1.3.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user