当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript typescript-collections.Set类代码示例

本文整理汇总了TypeScript中typescript-collections.Set的典型用法代码示例。如果您正苦于以下问题:TypeScript Set类的具体用法?TypeScript Set怎么用?TypeScript Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Set类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
    }
}
开发者ID:rustamli,项目名称:le-livre-bleu,代码行数:51,代码来源:dijkstra.ts

示例2: test

test('Generate cards for a standard deck', t => {
  t.plan(2);

  const cards = deckFactory.generateCardsForDeckType(deck_type.standard);
  const cardSet = new Set<string>();

  // Add all cards to a set, verify uniqueness by length
  cards.forEach(function(card: Card): void {
    let key = card.face.toString() + card.suit.toString();
    cardSet.add(key);
  });

  t.equal(cards.length, 52);
  t.equal(cardSet.size(), 52);
});
开发者ID:swese44,项目名称:deck,代码行数:15,代码来源:deckFactory.test.ts

示例3: dfs

export default function dfs(startNode: string, visit: Function) {
    
    var visited = new Collections.Set<string>(),
        search = (node: string) => {
            Graph.doWithConnectedNodes(node, function (connectedNode: string) {
                if (!visited.contains(connectedNode)) {
                    visit(connectedNode);
                    visited.add(connectedNode);
                    search(connectedNode);
                }
            });
        };

    visit(startNode);
    visited.add(startNode);
    search(startNode);
}
开发者ID:rustamli,项目名称:le-livre-bleu,代码行数:17,代码来源:dfs.ts

示例4: bfs

export default function bfs(startNode: string, visit: Function) {
    
    var visited = new Collections.Set<string>(),
        queue = new Collections.Queue<string>();

    visit(startNode);
    visited.add(startNode);
    queue.enqueue(startNode);

    while (!queue.isEmpty()) {
        let current = queue.dequeue();

        Graph.doWithConnectedNodes(current, function (connectedNode: string) {
            if (!visited.contains(connectedNode)) {
                visit(connectedNode);
                visited.add(connectedNode);
                queue.enqueue(connectedNode);
            }
        });
    }
}
开发者ID:rustamli,项目名称:le-livre-bleu,代码行数:21,代码来源:bfs.ts

示例5:

 cards.forEach(function(card: Card): void {
   let key = card.face.toString() + card.suit.toString();
   cardSet.add(key);
 });
开发者ID:swese44,项目名称:deck,代码行数:4,代码来源:deckFactory.test.ts


注:本文中的typescript-collections.Set类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。