diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-29 07:19:10 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-29 07:19:10 +0200 |
commit | 705b7a5a32793f7ed8a24b8b35afe3f9d49348be (patch) | |
tree | 7cffeb0de03a4638b87f04e01e7193eacbeaeede /src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java | |
parent | a5c3599d7bc7a9ef5583ad2d50a55975f030fbea (diff) |
tidy whitespace
Diffstat (limited to 'src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java')
-rw-r--r-- | src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java b/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java index 353f934..e85db6c 100644 --- a/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java +++ b/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java @@ -8,42 +8,46 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -/// Adjecency Map Graph - A map from vertices to map of target vertex to edge +/// Adjecency Map Graph - A map from vertices to map of target vertex to edge class AdjMapGraph extends AbstractGraph { - /// foo - AdjMapGraph() {} - - /// foo - private Map<Vertex, Map<Vertex, Edge>> outEdge = new HashMap<>(); - - /// foo - public void insertEdge(final Vertex v1, final Vertex v2, final int w) { - Edge e = new Edge(v1,v2, w); - if (!outEdge.containsKey(e.from())) - outEdge.put(e.from(), new HashMap<Vertex, Edge>()); - outEdge.get(e.from()).put(e.to(), e); - } - - /// foo - public Collection<Edge> edges() { - Set<Edge> edges = new HashSet<>(); - for (Vertex v : outEdge.keySet()) - for (Vertex w : outEdge.get(v).keySet()) - edges.add(outEdge.get(v).get(w)); - return edges; - } - - /// foo - public Collection<Edge> outEdge(final Vertex v) { - return outEdge.get(v).values(); - } - - /// foo - public Integer getWeight(final Vertex v1, final Vertex v2) { - // constant time operation - if(!outEdge.containsKey(v1))return null; - if(!outEdge.get(v1).containsKey(v2))return null; - return outEdge.get(v1).get(v2).weight(); - } + /// foo + AdjMapGraph() { } + + /// foo + private Map<Vertex, Map<Vertex, Edge>> outEdge = new HashMap<>(); + + /// foo + public void insertEdge(final Vertex v1, final Vertex v2, final int w) { + Edge e = new Edge(v1,v2, w); + if (!outEdge.containsKey(e.from())) + outEdge.put(e.from(), new HashMap<Vertex, Edge>()); + outEdge.get(e.from()).put(e.to(), e); + } + + /// foo + public Collection<Edge> edges() { + Set<Edge> edges = new HashSet<>(); + for (Vertex v : outEdge.keySet()) + for (Vertex w : outEdge.get(v).keySet()) + edges.add(outEdge.get(v).get(w)); + + return edges; + } + + /// foo + public Collection<Edge> outEdge(final Vertex v) { + return outEdge.get(v).values(); + } + + /// foo + public Integer getWeight(final Vertex v1, final Vertex v2) { + // constant time operation + if (!outEdge.containsKey(v1)) + return null; + if (!outEdge.get(v1).containsKey(v2)) + return null; + + return outEdge.get(v1).get(v2).weight(); + } } |