本文整理汇总了Python中sortedcontainers.SortedSet.discard方法的典型用法代码示例。如果您正苦于以下问题:Python SortedSet.discard方法的具体用法?Python SortedSet.discard怎么用?Python SortedSet.discard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedSet
的用法示例。
在下文中一共展示了SortedSet.discard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_discard
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import discard [as 别名]
def test_discard():
temp = SortedSet(range(100), load=7)
temp.discard(0)
temp.discard(99)
temp.discard(50)
temp.discard(1000)
temp._check()
assert len(temp) == 97
示例2: containsNearbyAlmostDuplicate
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import discard [as 别名]
def containsNearbyAlmostDuplicate(self, nums, k, t):
"""
:type nums: List[int]
:type k: int
:type t: int
:rtype: bool
"""
if k < 1 or t < 0 or nums == None or len(nums) < 2:
return False
treeset = SortedSet()
for i in xrange(len(nums)):
# Solution 1
subset = [x for x in treeset.irange(nums[i] - t, nums[i] + t)]
if len(subset) > 0:
return True
treeset.add(nums[i])
if i >= k:
treeset.discard(nums[i - k])
return False
示例3: SocialNetwork
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import discard [as 别名]
#.........这里部分代码省略.........
# add the node
g.add_node(id, st=st, nst=st, r_index=r_index)
self.node_set.add(id)
self.fitness_of[r_index] = id
self.fitness[r_index] = 0
# update parameters of the graph
if id > self.count:
self.count = id
self.size += 1
self.count += 1
# add edges from the seed to the network
for e0, e1 in seed.edges_iter():
g.add_edge(e0, e1)
self.__remove_isolated_nodes()
def __remove_isolated_nodes(self):
g = self.g
to_remove = []
for n, adj in g.adj.items():
if (len(adj) == 0):
to_remove.append(n)
for n in to_remove:
r_index = g.node[n]['r_index']
self.fitness_of[r_index] = -1
self.free_indexes.append(r_index)
self.node_set.discard(n)
g.remove_node(n)
self.size -= 1
def add_node(self, st):
""" Add a node to the network
"""
# calculate rest of the node attributes
id = self.count
r_index = self.free_indexes.pop()
# add node
self.g.add_node(id, st=st, nst=st, r_index=r_index, gen=self.gen)
# update network structures
self.node_set.add(id)
self.fitness_of[r_index] = id
self.fitness[r_index] = 0
self.degrees[r_index] = 0
# update network parameters
if st == COOP:
self.cooperators += 1
self.size += 1
self.count += 1
return id
def play_games_and_remove_isolated_nodes(self):
g = self.g
node = g.node
node_set = self.node_set