From c732b309a14696f60100440871c90789d443ad24 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 29 Feb 2016 09:01:16 -0500 Subject: Changed interface of GenHolder GenHolder now has a proper interface with no public fields --- .../main/java/bjc/utils/graph/AdjacencyMap.java | 9 +++++---- .../src/main/java/bjc/utils/graph/Graph.java | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/graph') diff --git a/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java b/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java index 3b6d6ef..d3a420e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/graph/AdjacencyMap.java @@ -48,12 +48,13 @@ public class AdjacencyMap { int col = 0; for (String part : parts) { - aMap.setWeight(row.held, col, Integer.parseInt(part)); + aMap.setWeight(row.unwrap(vl -> vl), col, + Integer.parseInt(part)); col++; } - row.held++; + row.transform((vl) -> vl + 1); }); scn.close(); @@ -96,11 +97,11 @@ public class AdjacencyMap { int rhs = adjMap.get(tgt.getKey()).get(src.getKey()); if (lhs != rhs) { - res.held = false; + res.transform((vl) -> false); } })); - return res.held; + return res.unwrap(vl -> vl); } /** 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 { // Start at the initial vertex and visit it GenHolder 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(src.held, tgt, weight))); + (tgt, weight) -> availEdges.add(new Edge( + src.unwrap(vl -> vl), tgt, weight))); // Get the edge with the minimum distance - Edge minEdge = availEdges.poll(); + GenHolder> 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; -- cgit v1.2.3