fix weighted shortest path result not stable (#1280)

Change-Id: Ic97d8c92bd97d6203b7b366a2c6e2f661932e05f
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 6706080..04680da 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 @@
     @Override
     public String writeWeightedPaths(WeightedPaths paths,
                                      Iterator<Vertex> vertices) {
-        return JsonUtil.toJson(ImmutableMap.of("paths", paths.toMap(),
+        Map<Id, Map<String, Object>> 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 053767f..9b89be5 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 @@
             Map<Id, NodeWithWeight> sorted = CollectionUtil.sortByValue(
                                              this.findingNodes, true);
             double minWeight = 0;
-            Set<NodeWithWeight> newSources = new HashSet<>();
+            Set<NodeWithWeight> newSources = InsertionOrderUtil.newSet();
             for (Map.Entry<Id, NodeWithWeight> entry : sorted.entrySet()) {
                 Id id = entry.getKey();
                 NodeWithWeight wn = entry.getValue();
@@ -265,7 +267,7 @@
         }
     }
 
-    public static class WeightedPaths extends HashMap<Id, NodeWithWeight> {
+    public static class WeightedPaths extends LinkedHashMap<Id, NodeWithWeight> {
 
         private static final long serialVersionUID = -313873642177730993L;