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

Method irange_key

sortedcontainers/sortedlist.py:2150–2231  ·  view source on GitHub ↗

Create an iterator of values between `min_key` and `max_key`. Both `min_key` and `max_key` default to `None` which is automatically inclusive of the beginning and end of the sorted-key list. The argument `inclusive` is a pair of booleans that indicates whether the m

(self, min_key=None, max_key=None, inclusive=(True, True),
                   reverse=False)

Source from the content-addressed store, hash-verified

2148
2149
2150 def irange_key(self, min_key=None, max_key=None, inclusive=(True, True),
2151 reverse=False):
2152 """Create an iterator of values between `min_key` and `max_key`.
2153
2154 Both `min_key` and `max_key` default to `None` which is automatically
2155 inclusive of the beginning and end of the sorted-key list.
2156
2157 The argument `inclusive` is a pair of booleans that indicates whether
2158 the minimum and maximum ought to be included in the range,
2159 respectively. The default is ``(True, True)`` such that the range is
2160 inclusive of both minimum and maximum.
2161
2162 When `reverse` is `True` the values are yielded from the iterator in
2163 reverse order; `reverse` defaults to `False`.
2164
2165 >>> from operator import neg
2166 >>> skl = SortedKeyList([11, 12, 13, 14, 15], key=neg)
2167 >>> it = skl.irange_key(-14, -12)
2168 >>> list(it)
2169 [14, 13, 12]
2170
2171 :param min_key: minimum key to start iterating
2172 :param max_key: maximum key to stop iterating
2173 :param inclusive: pair of booleans
2174 :param bool reverse: yield values in reverse order
2175 :return: iterator
2176
2177 """
2178 _maxes = self._maxes
2179
2180 if not _maxes:
2181 return iter(())
2182
2183 _keys = self._keys
2184
2185 # Calculate the minimum (pos, idx) pair. By default this location
2186 # will be inclusive in our calculation.
2187
2188 if min_key is None:
2189 min_pos = 0
2190 min_idx = 0
2191 else:
2192 if inclusive[0]:
2193 min_pos = bisect_left(_maxes, min_key)
2194
2195 if min_pos == len(_maxes):
2196 return iter(())
2197
2198 min_idx = bisect_left(_keys[min_pos], min_key)
2199 else:
2200 min_pos = bisect_right(_maxes, min_key)
2201
2202 if min_pos == len(_maxes):
2203 return iter(())
2204
2205 min_idx = bisect_right(_keys[min_pos], min_key)
2206
2207 # Calculate the maximum (pos, idx) pair. By default this location

Callers 3

test_irange_keyFunction · 0.95
test_irange_keyFunction · 0.80
test_irange_keyFunction · 0.80

Calls 2

_isliceMethod · 0.80
iterFunction · 0.50

Tested by 3

test_irange_keyFunction · 0.76
test_irange_keyFunction · 0.64
test_irange_keyFunction · 0.64