   id++;
            }
        }

        edges.sort(
            function (a, b) {
                if (a.distance > b.distance) {
                    return 1;
                } else if (b.distance > a.distance) {
                    return -1;
                } else {
                    return 0;
                }
            }
        );

        q1.all_neighbors = [];
        for (i = 0; i < maxNeighbors && i < edges.length; i++) {
            var edge = edges[i];
            q1.all_neighbors.push(edge