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


Python prioritydict.PriorityDict类代码示例

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


在下文中一共展示了PriorityDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_iloc_delitem_slice

def test_iloc_delitem_slice():
    temp = PriorityDict(enumerate(string.lowercase))
    that = list(enumerate(string.lowercase))
    del temp.iloc[5:20:3]
    del that[5:20:3]
    assert temp.items() == that
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:7,代码来源:test_coverage.py

示例2: test_len

def test_len():
    temp = PriorityDict()
    assert len(temp) == 0
    val = dict((letter, pos) for pos, letter in enumerate(string.lowercase))
    temp.update(val)
    assert len(temp) == 26
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:7,代码来源:test_coverage.py

示例3: test_isub_small

def test_isub_small():
    temp = PriorityDict((val, val) for val in range(100))
    that = PriorityDict((val, val) for val in range(10))
    temp -= that
    assert all(temp[val] == 0 for val in range(10))
    assert all(temp[val] == val for val in range(10, 100))
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:7,代码来源:test_coverage.py

示例4: test_iand_big

def test_iand_big():
    temp_vals = list((val, rand(100)) for val in range(100))
    that_vals = list((val, rand(100)) for val in range(100))
    temp = PriorityDict(temp_vals)
    that = PriorityDict(that_vals)
    temp &= that
    assert all(temp[pos] == min(temp_vals[pos][1], that_vals[pos][1])
               for pos in range(100))
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:9,代码来源:test_coverage.py

示例5: test_iloc_delitem

def test_iloc_delitem():
    temp = PriorityDict(enumerate(string.lowercase))
    that = list(enumerate(string.lowercase))

    while len(temp) > 0:
        pos = rand(len(temp))
        del that[pos]
        del temp.iloc[pos]
        assert temp.items() == that
        temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:10,代码来源:test_coverage.py

示例6: test_ior_small

def test_ior_small():
    temp_vals = list((val, rand(100)) for val in range(100))
    that_vals = list((val, rand(100)) for val in range(10))
    temp = PriorityDict(temp_vals)
    that = PriorityDict(that_vals)
    temp |= that
    assert all(temp[pos] == max(temp_vals[pos][1], that_vals[pos][1])
               for pos in range(10))
    assert all(temp[pos] == temp_vals[pos][1]
               for pos in range(10, 100))
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:11,代码来源:test_coverage.py

示例7: test_clean

def test_clean():
    temp = PriorityDict((val, num) for num, val in enumerate(string.lowercase))
    assert len(temp) == 26
    temp.clean()
    temp._check()
    assert len(temp) == 25
    temp.clean(10)
    temp._check()
    assert len(temp) == 15
开发者ID:grantjenks,项目名称:prioritydict,代码行数:9,代码来源:test_coverage.py

示例8: calculate_shortest_paths_from

    def calculate_shortest_paths_from(self, source_id):
        distance = {}
        previous = {}
        q = None
        if self.use_priority_queue:
            q = PriorityDict()
        else:
            q = []
        ind = []
        distance[source_id] = 0
        for x in self.nodes:
            if x is not source_id:
                distance[x] = float("inf")
                previous[x] = None
            if self.use_priority_queue:
                q[x] = distance[x]
            else:
                q.append(x)

        while len(q):
            u = None
            if self.use_priority_queue:
                u = q.pop_smallest()
            else:
                u = self.get_node_with_minimum_distance(q, distance, ind)
                index = ind.pop()
                if type(index) is int:
                    del q[index]
                else:
                    break

            if isinstance(self.edges[u], dict):
                for v in self.edges[u]:
                    if v in q:
                        alt = distance[u] + self.edges[u][v].strength
                        if alt < distance[v]:
                            distance[v] = alt
                            previous[v] = u
                            if self.use_priority_queue:
                                q[v] = distance[v]
        if not self.num_threads:
            self.shortest_paths[source_id] = distance
            self.shortest_paths_guide[source_id] = previous
        else:
            self.lock.acquire()
            self.shortest_paths[source_id] = distance
            self.shortest_paths_guide[source_id] = previous
            self.lock.release()
        return
开发者ID:sushanttripathy,项目名称:graphene,代码行数:49,代码来源:dijkstra.py

示例9: test_setdefault

def test_setdefault():
    temp = PriorityDict((val, key) for key, val in enumerate(string.lowercase))
    assert temp.setdefault('d', -1) == 3
    assert temp.setdefault('blah', 10) == 10
    temp._check()
    assert len(temp) == 27
    assert temp['k'] == 10
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:8,代码来源:test_coverage.py

示例10: test_iloc_getitem

def test_iloc_getitem():
    temp = PriorityDict(enumerate(string.lowercase))
    for pos, letter in enumerate(string.lowercase):
        assert temp[temp.iloc[pos]] == letter
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:5,代码来源:test_coverage.py

示例11: test_isdisjoint

def test_isdisjoint():
    temp = PriorityDict((val, val) for val in range(50))
    that = PriorityDict((val, val) for val in range(50, 100))
    assert temp.isdisjoint(that)
开发者ID:grantjenks,项目名称:prioritydict,代码行数:4,代码来源:test_coverage.py

示例12: test_delitem

def test_delitem():
    temp = PriorityDict(enumerate(string.lowercase))
    del temp[13]
    assert len(temp) == 25
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:5,代码来源:test_coverage.py

示例13: test_contains

def test_contains():
    temp = PriorityDict(enumerate(string.lowercase))
    assert all(pos in temp for pos in range(len(string.lowercase)))
    assert 26 not in temp
    assert not (-1 in temp)
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:6,代码来源:test_coverage.py

示例14: test_tally

def test_tally():
    temp = PriorityDict((val, key) for key, val in enumerate(string.lowercase))
    temp.tally(list(string.lowercase))
    for pos, key in enumerate(string.lowercase):
        assert temp[key] == (pos + 1)
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:6,代码来源:test_coverage.py

示例15: test_pop

def test_pop():
    temp = PriorityDict((val, key) for key, val in enumerate(string.lowercase))
    assert temp.pop('c') == 2
    temp._check()
    assert temp.pop('blah', -1) == -1
    temp._check()
开发者ID:grantjenks,项目名称:prioritydict,代码行数:6,代码来源:test_coverage.py


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