本文整理汇总了TypeScript中typescript-collections.Set.remove方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Set.remove方法的具体用法?TypeScript Set.remove怎么用?TypeScript Set.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typescript-collections.Set
的用法示例。
在下文中一共展示了Set.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dijkstra
function dijkstra(source, target) {
var unvisited = new Collections.Set(),
dist = {},
prev = {};
Graph.nodes.forEach(function (node) {
dist[node] = INFINITY;
prev[node] = null;
unvisited.add(node);
});
dist[source] = 0;
var currentNode = source,
pathExists = true;
while (currentNode != target) {
unvisited.remove(currentNode);
Graph.doWithConnectedNodes(currentNode, (node: string, weight: number) => {
var distFromCurrentNode = dist[currentNode] + weight;
if (dist[node] > distFromCurrentNode) {
dist[node] = distFromCurrentNode;
prev[node] = currentNode;
}
});
currentNode = null;
unvisited.forEach(function (node: string) {
if (!currentNode || dist[currentNode] > dist[node]) {
currentNode = node;
}
});
if (dist[currentNode] === INFINITY) {
console.log('No path was found');
pathExists = false;
break;
}
}
if (pathExists) {
while (currentNode != source) {
console.log(currentNode);
currentNode = prev[currentNode];
}
console.log(source);
}
}