本文整理汇总了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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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
示例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()
示例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()
示例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)
示例12: test_delitem
def test_delitem():
temp = PriorityDict(enumerate(string.lowercase))
del temp[13]
assert len(temp) == 25
temp._check()
示例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()
示例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()
示例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()