summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-02-29 09:01:16 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-02-29 09:01:16 -0500
commitc732b309a14696f60100440871c90789d443ad24 (patch)
treeec83783687c44e6fbb6d367b15e1c43cee75f38c /BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
parenta5f6bd475293d72e040a2dbb92eb145e47c09fe5 (diff)
Changed interface of GenHolder
GenHolder now has a proper interface with no public fields
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
index 03bc0c2..ca3d06f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/graph/Graph.java
@@ -137,34 +137,36 @@ public class Graph<T> {
// Start at the initial vertex and visit it
GenHolder<T> src = new GenHolder<>(getInitial());
- visited.add(src.held);
+ visited.add(src.unwrap(vl -> vl));
// Make sure we visit all the nodes
while (visited.size() != getVertexCount()) {
// Grab all edges adjacent to the provided edge
- forAllEdgesMatchingAt(src.held,
+ forAllEdgesMatchingAt(src.unwrap(vl -> vl),
(tgt, weight) -> !visited.contains(tgt),
- (tgt, weight) -> availEdges
- .add(new Edge<T>(src.held, tgt, weight)));
+ (tgt, weight) -> availEdges.add(new Edge<T>(
+ src.unwrap(vl -> vl), tgt, weight)));
// Get the edge with the minimum distance
- Edge<T> minEdge = availEdges.poll();
+ GenHolder<Edge<T>> minEdge = new GenHolder<>(
+ availEdges.poll());
// Only consider edges where we haven't visited the target of
// the edge
- while (visited.contains(minEdge.getTarget())) {
- minEdge = availEdges.poll();
+ while (visited
+ .contains(minEdge.unwrap(vl -> vl.getTarget()))) {
+ minEdge.transform((vl) -> availEdges.poll());
}
// Add it to our MST
- minEdges.add(minEdge);
+ minEdges.add(minEdge.unwrap(vl -> vl));
// Advance to the next node
- src.held = minEdge.getTarget();
+ src.transform((vl) -> minEdge.unwrap(vl1 -> vl1.getTarget()));
// Visit this node
- visited.add(src.held);
+ visited.add(src.unwrap(vl -> vl));
}
return minEdges;