本文整理汇总了Python中_collections.deque方法的典型用法代码示例。如果您正苦于以下问题:Python _collections.deque方法的具体用法?Python _collections.deque怎么用?Python _collections.deque使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_collections
的用法示例。
在下文中一共展示了_collections.deque方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def __init__(self, lock=None):
if lock is None:
lock = RLock()
self._lock = lock
# Export the lock's acquire() and release() methods
self.acquire = lock.acquire
self.release = lock.release
# If the lock defines _release_save() and/or _acquire_restore(),
# these override the default implementations (which just call
# release() and acquire() on the lock). Ditto for _is_owned().
try:
self._release_save = lock._release_save
except AttributeError:
pass
try:
self._acquire_restore = lock._acquire_restore
except AttributeError:
pass
try:
self._is_owned = lock._is_owned
except AttributeError:
pass
self._waiters = _deque()
示例2: notify
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def notify(self, n=1):
"""Wake up one or more threads waiting on this condition, if any.
If the calling thread has not acquired the lock when this method is
called, a RuntimeError is raised.
This method wakes up at most n of the threads waiting for the condition
variable; it is a no-op if no threads are waiting.
"""
if not self._is_owned():
raise RuntimeError("cannot notify on un-acquired lock")
all_waiters = self._waiters
waiters_to_notify = _deque(_islice(all_waiters, n))
if not waiters_to_notify:
return
for waiter in waiters_to_notify:
waiter.release()
try:
all_waiters.remove(waiter)
except ValueError:
pass
示例3: __init__
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def __init__(self, trace, title='Optimizations', **kwargs):
# context should be a dictionary containing the backward traced result of each relevant register
super(OptimizationViewer, self).__init__(title)
self.orig_trace = trace
self.trace = deepcopy(trace)
self.undo_stack = deque([deepcopy(trace), deepcopy(trace), deepcopy(trace)], maxlen=3)
self.opti_map = dict(zip(optimization_names, optimizations))
self.order = []
self.foldable_regs = []
self.save = kwargs.get('save', None)
示例4: __init__
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def __init__(self, trace, title='Optimizations (legacy)', **kwargs):
# context should be a dictionary containing the backward traced result of each relevant register
super(OptimizationViewer, self).__init__(title)
self.orig_trace = trace
self.trace = deepcopy(trace)
self.undo_stack = deque([deepcopy(trace), deepcopy(trace), deepcopy(trace)], maxlen=3)
self.opti_map = dict(zip(optimization_names, optimizations))
self.order = []
self.foldable_regs = []
self.save = kwargs.get('save', None)
示例5: __init__
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def __init__(self, clustered_trace, bb_func, ctx_reg_size, title='Clustering Analysis Result (legacy)', save_func=None):
# context should be a dictionary containing the backward traced result of each relevant register
super(ClusterViewer, self).__init__(title)
self.orig_trace = clustered_trace
self.trace = deepcopy(self.orig_trace)
self.bb_func = bb_func
self.ctx_reg_size = ctx_reg_size
self.save = save_func
self.undo_stack = deque([deepcopy(self.trace)], maxlen=3)
示例6: Restore
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def Restore(self):
self.undo_stack = deque([deepcopy(self.trace)], maxlen=3)
self.trace = deepcopy(self.orig_trace)
self.PopulateModel()
示例7: __init__
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def __init__(self, clustered_trace, bb_func, ctx_reg_size, title='Clustering Analysis Result', save_func=None):
# context should be a dictionary containing the backward traced result of each relevant register
super(ClusterViewer, self).__init__(title)
self.orig_trace = clustered_trace
self.trace = deepcopy(self.orig_trace)
self.bb_func = bb_func
self.ctx_reg_size = ctx_reg_size
self.save = save_func
self.undo_stack = deque([deepcopy(self.trace)], maxlen=3)
示例8: test_builtin_next
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def test_builtin_next():
from _collections import deque
values = [1,2,3,4]
iterable_list = [list, tuple, set, deque]
for iterable in iterable_list:
i = iter(iterable(values))
AreEqual(next(i), 1)
AreEqual(next(i), 2)
AreEqual(next(i), 3)
AreEqual(next(i), 4)
AssertError(StopIteration, next, i)
i = iter(iterable(values))
AreEqual(next(i, False), 1)
AreEqual(next(i, False), 2)
AreEqual(next(i, False), 3)
AreEqual(next(i, False), 4)
AreEqual(next(i, False), False)
AreEqual(next(i, False), False)
i = iter('abcdE')
AreEqual(next(i), 'a')
AreEqual(next(i), 'b')
AreEqual(next(i), 'c')
AreEqual(next(i), 'd')
AreEqual(next(i), 'E')
AssertError(StopIteration, next, i)
i = iter('edcbA')
AreEqual(next(i, False), 'e')
AreEqual(next(i, False), 'd')
AreEqual(next(i, False), 'c')
AreEqual(next(i, False), 'b')
AreEqual(next(i, False), 'A')
AreEqual(next(i, False), False)
AreEqual(next(i, False), False)
示例9: test_unhashable_types
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def test_unhashable_types(self):
import System
class OldUserClass:
def foo(): pass
import _weakref
from _collections import deque
self.assertRaises(TypeError, hash, slice(None))
hashcode = System.Object.GetHashCode(slice(None))
# weakproxy
self.assertRaises(TypeError, hash, _weakref.proxy(OldUserClass()))
hashcode = System.Object.GetHashCode(_weakref.proxy(OldUserClass()))
# weakcallableproxy
self.assertRaises(TypeError, hash, _weakref.proxy(OldUserClass().foo))
hashcode = System.Object.GetHashCode(_weakref.proxy(OldUserClass().foo))
self.assertRaises(TypeError, hash, deque())
hashcode = System.Object.GetHashCode(deque())
self.assertRaises(TypeError, hash, dict())
hashcode = System.Object.GetHashCode(dict())
self.assertRaises(TypeError, hash, list())
hashcode = System.Object.GetHashCode(list())
self.assertRaises(TypeError, hash, set())
hashcode = System.Object.GetHashCode(set())
示例10: _genericSuffixStripper
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def _genericSuffixStripper(self, initialState, word, stems, machine):
"""
Given the initial state of a state machine, it adds possible stems to a set of stems.
Args:
initialState (State): an initial state
word (str): the word to stem
stems (set): the set to populate
machine (str): a string representing the name of the state machine. It is used for debugging reasons only.
"""
transitions = deque()
initialState.AddTransitions(word, transitions, False)
while transitions:
transition = transitions.popleft()
wordToStem = transition.word
stem = self.stemWord(wordToStem, transition.suffix)
if stem != wordToStem:
if transition.nextState.finalState:
for transitionToRemove in tuple(transitions):
if ((transitionToRemove.startState == transition.startState and
transitionToRemove.nextState == transition.nextState) or
transitionToRemove.marked):
transitions.remove(transitionToRemove)
stems.add(stem)
transition.nextState.AddTransitions(stem, transitions, False)
else:
for similarTransition in transition.similarTransitions(transitions):
similarTransition.marked = True
transition.nextState.AddTransitions(stem, transitions, True)
示例11: test_unhashable_types
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def test_unhashable_types(self):
import System
class OldUserClass:
def foo(): pass
import _weakref
from _collections import deque
self.assertRaises(TypeError, hash, slice(None))
hashcode = System.Object.GetHashCode(slice(None))
# weakproxy
self.assertRaises(TypeError, hash, _weakref.proxy(OldUserClass()))
hashcode = System.Object.GetHashCode(_weakref.proxy(OldUserClass()))
# weakcallableproxy
self.assertRaises(TypeError, hash, _weakref.proxy(OldUserClass().foo))
hashcode = System.Object.GetHashCode(_weakref.proxy(OldUserClass().foo))
self.assertRaises(TypeError, hash, deque())
hashcode = System.Object.GetHashCode(deque())
self.assertRaises(TypeError, hash, dict())
hashcode = System.Object.GetHashCode(dict())
self.assertRaises(TypeError, hash, list())
hashcode = System.Object.GetHashCode(list())
self.assertRaises(TypeError, hash, set())
hashcode = System.Object.GetHashCode(set())
示例12: test_deque
# 需要导入模块: import _collections [as 别名]
# 或者: from _collections import deque [as 别名]
def test_deque(self):
if is_cli:
from _collections import deque
else:
from collections import deque
x = deque([2,3,4,5,6])
x.remove(2)
self.assertEqual(x, deque([3,4,5,6]))
x.remove(6)
self.assertEqual(x, deque([3,4,5]))
x.remove(4)
self.assertEqual(x, deque([3,5]))
# get a deque w/ head/tail backwards...
x = deque([1,2,3,4,5,6,7,8])
x.popleft()
x.popleft()
x.popleft()
x.popleft()
x.append(1)
x.append(2)
x.append(3)
x.append(4)
self.assertEqual(x, deque([5,6,7,8, 1, 2, 3, 4]))
x.remove(5)
self.assertEqual(x, deque([6,7,8, 1, 2, 3, 4]))
x.remove(4)
self.assertEqual(x, deque([6,7,8, 1, 2, 3]))
x.remove(8)
self.assertEqual(x, deque([6,7,1, 2, 3]))
x.remove(2)
self.assertEqual(x, deque([6,7,1, 3]))
class BadCmp:
def __eq__(self, other):
raise RuntimeError
d = deque([1,2, BadCmp()])
self.assertRaises(RuntimeError, d.remove, 3)
x = deque()
class y(object):
def __eq__(self, other):
return True
x.append(y())
self.assertEqual(y() in x, True)
x = deque({}, None)
self.assertEqual(x, deque([]))
self.assertRaisesPartialMessage(TypeError, "takes at most 2 arguments (3 given)", deque, 'abc', 2, 2)