mirror of https://gitee.com/bigwinds/arangodb
Faster Handling of shortest path if empty
This commit is contained in:
parent
0b0df398d0
commit
353b28d814
|
@ -697,7 +697,7 @@ Vertex.prototype.commonPropertiesWith = function (other_vertex, options) {
|
||||||
|
|
||||||
Vertex.prototype.pathTo = function (target_vertex, options) {
|
Vertex.prototype.pathTo = function (target_vertex, options) {
|
||||||
var predecessors = target_vertex.determinePredecessors(this, options || {});
|
var predecessors = target_vertex.determinePredecessors(this, options || {});
|
||||||
return target_vertex.pathesForTree(predecessors);
|
return (predecessors ? target_vertex.pathesForTree(predecessors) : []);
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -739,7 +739,8 @@ Vertex.prototype.determinePredecessors = function (source, options) {
|
||||||
todo_list = [source_id], // [ID]
|
todo_list = [source_id], // [ID]
|
||||||
distances = {}, // { ID => Number }
|
distances = {}, // { ID => Number }
|
||||||
current_vertex, // Vertex
|
current_vertex, // Vertex
|
||||||
current_vertex_id; // ID
|
current_vertex_id, // ID
|
||||||
|
return_value = false; // { ID => [ID]}
|
||||||
distances[source_id] = 0;
|
distances[source_id] = 0;
|
||||||
|
|
||||||
if (options.cached) {
|
if (options.cached) {
|
||||||
|
@ -753,6 +754,8 @@ Vertex.prototype.determinePredecessors = function (source, options) {
|
||||||
current_vertex = this._graph.getVertex(current_vertex_id);
|
current_vertex = this._graph.getVertex(current_vertex_id);
|
||||||
|
|
||||||
if (current_vertex_id === this.getId()) {
|
if (current_vertex_id === this.getId()) {
|
||||||
|
require("console").log("FOUND YOU!");
|
||||||
|
return_value = predecessors;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
todo_list.removeLastOccurrenceOf(current_vertex_id);
|
todo_list.removeLastOccurrenceOf(current_vertex_id);
|
||||||
|
@ -769,7 +772,7 @@ Vertex.prototype.determinePredecessors = function (source, options) {
|
||||||
graph.setCachedPredecessors(this, source, predecessors);
|
graph.setCachedPredecessors(this, source, predecessors);
|
||||||
}
|
}
|
||||||
|
|
||||||
return predecessors;
|
return return_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue