MCPcopy Create free account
hub / github.com/grantjenks/python-sortedcontainers / irange

Method irange

sortedcontainers/sortedlist.py:1072–1152  ·  view source on GitHub ↗

Create an iterator of values between `minimum` and `maximum`. Both `minimum` and `maximum` default to `None` which is automatically inclusive of the beginning and end of the sorted list. The argument `inclusive` is a pair of booleans that indicates whether the minim

(self, minimum=None, maximum=None, inclusive=(True, True),
               reverse=False)

Source from the content-addressed store, hash-verified

1070
1071
1072 def irange(self, minimum=None, maximum=None, inclusive=(True, True),
1073 reverse=False):
1074 """Create an iterator of values between `minimum` and `maximum`.
1075
1076 Both `minimum` and `maximum` default to `None` which is automatically
1077 inclusive of the beginning and end of the sorted list.
1078
1079 The argument `inclusive` is a pair of booleans that indicates whether
1080 the minimum and maximum ought to be included in the range,
1081 respectively. The default is ``(True, True)`` such that the range is
1082 inclusive of both minimum and maximum.
1083
1084 When `reverse` is `True` the values are yielded from the iterator in
1085 reverse order; `reverse` defaults to `False`.
1086
1087 >>> sl = SortedList('abcdefghij')
1088 >>> it = sl.irange('c', 'f')
1089 >>> list(it)
1090 ['c', 'd', 'e', 'f']
1091
1092 :param minimum: minimum value to start iterating
1093 :param maximum: maximum value to stop iterating
1094 :param inclusive: pair of booleans
1095 :param bool reverse: yield values in reverse order
1096 :return: iterator
1097
1098 """
1099 _maxes = self._maxes
1100
1101 if not _maxes:
1102 return iter(())
1103
1104 _lists = self._lists
1105
1106 # Calculate the minimum (pos, idx) pair. By default this location
1107 # will be inclusive in our calculation.
1108
1109 if minimum is None:
1110 min_pos = 0
1111 min_idx = 0
1112 else:
1113 if inclusive[0]:
1114 min_pos = bisect_left(_maxes, minimum)
1115
1116 if min_pos == len(_maxes):
1117 return iter(())
1118
1119 min_idx = bisect_left(_lists[min_pos], minimum)
1120 else:
1121 min_pos = bisect_right(_maxes, minimum)
1122
1123 if min_pos == len(_maxes):
1124 return iter(())
1125
1126 min_idx = bisect_right(_lists[min_pos], minimum)
1127
1128 # Calculate the maximum (pos, idx) pair. By default this location
1129 # will be exclusive in our calculation.

Callers 4

test_irangeFunction · 0.95
stress_irangeFunction · 0.45
test_irangeFunction · 0.45
test_irangeFunction · 0.45

Calls 2

_isliceMethod · 0.95
iterFunction · 0.50

Tested by 4

test_irangeFunction · 0.76
stress_irangeFunction · 0.36
test_irangeFunction · 0.36
test_irangeFunction · 0.36