diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java index 6706080dd4..04680da683 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/serializer/JsonSerializer.java @@ -287,7 +287,10 @@ public String writeWeightedPath(NodeWithWeight path, @Override public String writeWeightedPaths(WeightedPaths paths, Iterator vertices) { - return JsonUtil.toJson(ImmutableMap.of("paths", paths.toMap(), + Map> pathMap = paths == null ? + ImmutableMap.of() : + paths.toMap(); + return JsonUtil.toJson(ImmutableMap.of("paths", pathMap, "vertices", vertices)); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/SingleSourceShortestPathTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/SingleSourceShortestPathTraverser.java index 053767fef3..9b89be5b62 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/SingleSourceShortestPathTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/SingleSourceShortestPathTraverser.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -36,6 +37,7 @@ import com.baidu.hugegraph.type.define.Directions; import com.baidu.hugegraph.util.CollectionUtil; import com.baidu.hugegraph.util.E; +import com.baidu.hugegraph.util.InsertionOrderUtil; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -168,7 +170,7 @@ public void forward() { Map sorted = CollectionUtil.sortByValue( this.findingNodes, true); double minWeight = 0; - Set newSources = new HashSet<>(); + Set newSources = InsertionOrderUtil.newSet(); for (Map.Entry entry : sorted.entrySet()) { Id id = entry.getKey(); NodeWithWeight wn = entry.getValue(); @@ -265,7 +267,7 @@ public int compareTo(NodeWithWeight other) { } } - public static class WeightedPaths extends HashMap { + public static class WeightedPaths extends LinkedHashMap { private static final long serialVersionUID = -313873642177730993L;