本文整理汇总了Python中sortedcontainers.SortedSet.update方法的典型用法代码示例。如果您正苦于以下问题:Python SortedSet.update方法的具体用法?Python SortedSet.update怎么用?Python SortedSet.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedSet
的用法示例。
在下文中一共展示了SortedSet.update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_irange
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import update [as 别名]
def test_irange():
ss = SortedSet(load=7)
assert [] == list(ss.irange())
values = list(range(53))
ss.update(values)
for start in range(53):
for end in range(start, 53):
assert list(ss.irange(start, end)) == values[start:(end + 1)]
assert list(ss.irange(start, end, reverse=True)) == values[start:(end + 1)][::-1]
for start in range(53):
for end in range(start, 53):
assert list(range(start, end)) == list(ss.irange(start, end, (True, False)))
for start in range(53):
for end in range(start, 53):
assert list(range(start + 1, end + 1)) == list(ss.irange(start, end, (False, True)))
for start in range(53):
for end in range(start, 53):
assert list(range(start + 1, end)) == list(ss.irange(start, end, (False, False)))
for start in range(53):
assert list(range(start, 53)) == list(ss.irange(start))
for end in range(53):
assert list(range(0, end)) == list(ss.irange(None, end, (True, False)))
assert values == list(ss.irange(inclusive=(False, False)))
assert [] == list(ss.irange(53))
assert values == list(ss.irange(None, 53, (True, False)))
示例2: test_islice
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import update [as 别名]
def test_islice():
ss = SortedSet(load=7)
assert [] == list(ss.islice())
values = list(range(53))
ss.update(values)
for start in range(53):
for stop in range(53):
assert list(ss.islice(start, stop)) == values[start:stop]
for start in range(53):
for stop in range(53):
assert list(ss.islice(start, stop, reverse=True)) == values[start:stop][::-1]
for start in range(53):
assert list(ss.islice(start=start)) == values[start:]
assert list(ss.islice(start=start, reverse=True)) == values[start:][::-1]
for stop in range(53):
assert list(ss.islice(stop=stop)) == values[:stop]
assert list(ss.islice(stop=stop, reverse=True)) == values[:stop][::-1]
示例3: test_update
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import update [as 别名]
def test_update():
temp = SortedSet(range(0, 80), load=7)
temp.update(range(80, 90), range(90, 100))
assert all(temp[val] == val for val in range(100))
示例4: len
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import update [as 别名]
if state == '1:start':
prev_len = len(available_res)
(new_available, alloc) = take_first_resources(
available_res, job.nb_res)
available_res = new_available
job.resources = alloc
if len(job.resources) != job.nb_res:
raise Exception('Invalid number of resources ({}, expected {})'
.format(job.resources, job.nb_res))
if len(available_res) != prev_len - job.nb_res:
raise Exception('Invalid number of available resources '
'({}, expected {})'
.formta(len(available_res), prev_len - job.nb_res))
elif state == '0:finish':
available_res.update(job.resources)
##############
# Export CSV #
##############
writer = csv.DictWriter(args.outputCSV,
fieldnames=["job_id",
"submission_time",
"requested_number_of_resources",
"requested_time",
"success",
"starting_time",
"execution_time",
"finish_time",
"waiting_time",
示例5: in_place_stoplist
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import update [as 别名]
def in_place_stoplist(self, stoplist=None, freq=0):
"""
Changes a Corpus object with words in the stoplist removed and with
words of frequency <= `freq` removed.
:param stoplist: The list of words to be removed.
:type stoplist: list
:param freq: A threshold where words of frequency <= 'freq' are
removed. Default is 0.
:type freq: integer, optional
:returns: Copy of corpus with words in the stoplist and words
of frequnecy <= 'freq' removed.
:See Also: :class:`Corpus`
"""
from sortedcontainers import SortedSet, SortedList
stop = SortedSet()
if stoplist:
for t in stoplist:
if t in self.words_int:
stop.add(self.words_int[t])
if freq:
cfs = np.bincount(self.corpus)
freq_stop = np.where(cfs <= freq)[0]
stop.update(freq_stop)
if not stop:
# print 'Stop list is empty.'
return self
# print 'Removing stop words', datetime.now()
f = np.vectorize(stop.__contains__)
# print 'Rebuilding context data', datetime.now()
context_data = []
BASE = len(self.context_data) - 1
# gathering list of new indicies from narrowest tokenization
def find_new_indexes(INTO, BASE=-1):
locs = np.where(np.in1d(self.context_data[BASE]['idx'], self.context_data[INTO]['idx']))[0]
# creating a list of lcoations that are non-identical
new_locs = np.array([loc for i, loc in enumerate(locs)
if i+1 == len(locs) or self.context_data[BASE]['idx'][locs[i]] != self.context_data[BASE]['idx'][locs[i+1]]])
# creating a search for locations that ARE identical
idxs = np.insert(self.context_data[INTO]['idx'], [0,-1], [-1,-1])
same_spots = np.where(np.equal(idxs[:-1], idxs[1:]))[0]
# readding the identical locations
really_new_locs = np.insert(new_locs, same_spots, new_locs[same_spots-1])
return really_new_locs
# Calculate new base tokens
tokens = self.view_contexts(self.context_types[BASE])
new_corpus = []
spans = []
for t in tokens:
new_t = t[np.logical_not(f(t))] if t.size else t
# TODO: append to new_corpus as well
spans.append(new_t.size if new_t.size else 0)
if new_t.size:
new_corpus.append(new_t)
# Stopped all words from Corpus
if not new_corpus:
return Corpus([])
new_base = self.context_data[BASE].copy()
new_base['idx'] = np.cumsum(spans)
context_data = []
# calculate new tokenizations for every context_type
for i in xrange(len(self.context_data)):
if i == BASE:
context_data.append(new_base)
else:
context = self.context_data[i].copy()
context['idx'] = new_base['idx'][find_new_indexes(i, BASE)]
context_data.append(context)
del self.context_data
self.context_data = context_data
# print 'Rebuilding corpus and updating stop words', datetime.now()
self.corpus = np.concatenate(new_corpus)
#self.corpus[f(self.corpus)]
self.stopped_words.update(self.words[stop])
#print 'adjusting words list', datetime.now()
new_words = np.delete(self.words, stop)
# print 'rebuilding word dictionary', datetime.now()
new_words_int = dict((word,i) for i, word in enumerate(new_words))
#.........这里部分代码省略.........
示例6: stress_issubset
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import update [as 别名]
def stress_issubset(sst):
that = SortedSet(sst)
that.update(range(1000))
assert sst.issubset(that)