Skip to content

Commit

Permalink
Minor changes for predictable ordering (jgrapht#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-michail authored Apr 28, 2021
1 parent 37f2b43 commit ffb5e50
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public Partitioning<V> getPartitioning()
return cachedPartitioning;
}

Set<V> unknown = new HashSet<>(graph.vertexSet());
Set<V> odd = new HashSet<>();
Set<V> unknown = new LinkedHashSet<>(graph.vertexSet());
Set<V> odd = new LinkedHashSet<>();
Deque<V> queue = new ArrayDeque<>();

while (!unknown.isEmpty()) {
Expand All @@ -119,7 +119,7 @@ public Partitioning<V> getPartitioning()
}
}

Set<V> even = new HashSet<>(graph.vertexSet());
Set<V> even = new LinkedHashSet<>(graph.vertexSet());
even.removeAll(odd);

computed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
*/
package org.jgrapht.traverse;

import org.jgrapht.*;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

import java.lang.reflect.*;
import java.util.*;
import org.jgrapht.Graph;
import org.jgrapht.Graphs;

/**
* A degeneracy ordering iterator.
Expand Down Expand Up @@ -88,7 +93,7 @@ public DegeneracyOrderingIterator(Graph<V, E> graph)
*/
this.buckets = (Set<V>[]) Array.newInstance(Set.class, maxDegree + 1);
for (int i = 0; i < buckets.length; i++) {
buckets[i] = new HashSet<>();
buckets[i] = new LinkedHashSet<>();
}
for (V v : graph.vertexSet()) {
buckets[degrees.get(v)].add(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
*/
package org.jgrapht.traverse;

import org.jgrapht.*;
import org.jgrapht.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

import java.util.*;
import org.jgrapht.Graph;
import org.jgrapht.GraphTests;
import org.jgrapht.Graphs;
import org.jgrapht.util.CollectionUtil;

/**
* A lexicographical breadth-first iterator for an undirected graph.
Expand Down Expand Up @@ -162,7 +169,7 @@ private V advance()
*/
private Set<V> getUnvisitedNeighbours(V vertex)
{
Set<V> unmapped = new HashSet<>();
Set<V> unmapped = new LinkedHashSet<>();
Set<E> edges = graph.edgesOf(vertex);
for (E edge : edges) {
V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
Expand Down Expand Up @@ -311,7 +318,7 @@ private class Bucket
*/
Bucket(Collection<V> vertices)
{
this.vertices = new HashSet<>(vertices);
this.vertices = new LinkedHashSet<>(vertices);
}

/**
Expand All @@ -321,7 +328,7 @@ private class Bucket
*/
Bucket(V vertex)
{
this.vertices = new HashSet<>();
this.vertices = new LinkedHashSet<>();
vertices.add(vertex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testGraph1()
String v = it.next();
sb.append("," + v);
}
assertEquals(",v8,v6,v7,v5,v9,v10,v1,v2,v3,v4", sb.toString());
assertEquals(",v8,v6,v7,v5,v9,v10,v3,v4,v1,v2", sb.toString());
}

@Test
Expand Down Expand Up @@ -116,7 +116,7 @@ public void testGraphWithListener()
it.next();
}
assertEquals(
",s_a,f_a,s_b,f_b,s_d,f_d,s_c,f_c,s_j,f_j,s_i,f_i,s_k,f_k,s_e,f_e,s_f,f_f,s_g,f_g,s_h,f_h",
",s_a,f_a,s_b,f_b,s_d,f_d,s_c,f_c,s_j,f_j,s_k,f_k,s_i,f_i,s_g,f_g,s_h,f_h,s_e,f_e,s_f,f_f",
listener.toString());
}

Expand Down

0 comments on commit ffb5e50

Please sign in to comment.