text
stringlengths
0
828
200,"def sync(self):
""""""
execute the steps required to have the
feature end with the desired state.
""""""
phase = _get_phase(self._formula_instance)
self.logger.info(""%s %s..."" % (phase.verb.capitalize(), self.feature_name))
message = ""...finished %s %s."" % (phase.verb, self.feature_name)
result = getattr(self, phase.name)()
if result or phase in (PHASE.INSTALL, PHASE.REMOVE):
self.logger.info(message)
else:
self.logger.debug(message)
return result"
201,"def linear_insert(self, item, priority):
""""""Linear search. Performance is O(n^2).""""""
with self.lock:
self_data = self.data
rotate = self_data.rotate
maxlen = self._maxlen
length = len(self_data)
count = length
# in practice, this is better than doing a rotate(-1) every
# loop and getting self.data[0] each time only because deque
# implements a very efficient iterator in C
for i in self_data:
if priority > i[1]:
break
count -= 1
rotate(-count)
self_data.appendleft((item, priority))
rotate(length-count)
try:
self.items[item] += 1
except TypeError:
self.items[repr(item)] += 1
if maxlen is not None and maxlen < len(self_data):
self._poplast()"
202,"def binary_insert(self, item, priority):
""""""Traditional binary search. Performance: O(n log n)""""""
with self.lock:
self_data = self.data
rotate = self_data.rotate
maxlen = self._maxlen
length = len(self_data)
index = 0
min = 0
max = length - 1
while max - min > 10:
mid = (min + max) // 2
# If index in 1st half of list
if priority > self_data[mid][1]:
max = mid - 1
# If index in 2nd half of list
else:
min = mid + 1
for i in range(min, max + 1):
if priority > self_data[i][1]:
index = i
break
elif i == max:
index = max + 1
shift = length - index
# Never shift more than half length of depq
if shift > length // 2:
shift = length % shift
rotate(-shift)
self_data.appendleft((item, priority))
rotate(shift)
else:
rotate(shift)
self_data.append((item, priority))
rotate(-shift)
try:
self.items[item] += 1
except TypeError:
self.items[repr(item)] += 1
if maxlen is not None and maxlen < len(self_data):
self._poplast()"
203,"def isloaded(self, name):
""""""Checks if given hook module has been loaded
Args:
name (str): The name of the module to check