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

Method _islice

sortedcontainers/sortedlist.py:1008–1069  ·  view source on GitHub ↗

Return an iterator that slices sorted list using two index pairs. The index pairs are (min_pos, min_idx) and (max_pos, max_idx), the first inclusive and the latter exclusive. See `_pos` for details on how an index is converted to an index pair. When `reverse` is `Tr

(self, min_pos, min_idx, max_pos, max_idx, reverse)

Source from the content-addressed store, hash-verified

1006
1007
1008 def _islice(self, min_pos, min_idx, max_pos, max_idx, reverse):
1009 """Return an iterator that slices sorted list using two index pairs.
1010
1011 The index pairs are (min_pos, min_idx) and (max_pos, max_idx), the
1012 first inclusive and the latter exclusive. See `_pos` for details on how
1013 an index is converted to an index pair.
1014
1015 When `reverse` is `True`, values are yielded from the iterator in
1016 reverse order.
1017
1018 """
1019 _lists = self._lists
1020
1021 if min_pos > max_pos:
1022 return iter(())
1023
1024 if min_pos == max_pos:
1025 if reverse:
1026 indices = reversed(range(min_idx, max_idx))
1027 return map(_lists[min_pos].__getitem__, indices)
1028
1029 indices = range(min_idx, max_idx)
1030 return map(_lists[min_pos].__getitem__, indices)
1031
1032 next_pos = min_pos + 1
1033
1034 if next_pos == max_pos:
1035 if reverse:
1036 min_indices = range(min_idx, len(_lists[min_pos]))
1037 max_indices = range(max_idx)
1038 return chain(
1039 map(_lists[max_pos].__getitem__, reversed(max_indices)),
1040 map(_lists[min_pos].__getitem__, reversed(min_indices)),
1041 )
1042
1043 min_indices = range(min_idx, len(_lists[min_pos]))
1044 max_indices = range(max_idx)
1045 return chain(
1046 map(_lists[min_pos].__getitem__, min_indices),
1047 map(_lists[max_pos].__getitem__, max_indices),
1048 )
1049
1050 if reverse:
1051 min_indices = range(min_idx, len(_lists[min_pos]))
1052 sublist_indices = range(next_pos, max_pos)
1053 sublists = map(_lists.__getitem__, reversed(sublist_indices))
1054 max_indices = range(max_idx)
1055 return chain(
1056 map(_lists[max_pos].__getitem__, reversed(max_indices)),
1057 chain.from_iterable(map(reversed, sublists)),
1058 map(_lists[min_pos].__getitem__, reversed(min_indices)),
1059 )
1060
1061 min_indices = range(min_idx, len(_lists[min_pos]))
1062 sublist_indices = range(next_pos, max_pos)
1063 sublists = map(_lists.__getitem__, sublist_indices)
1064 max_indices = range(max_idx)
1065 return chain(

Callers 3

isliceMethod · 0.95
irangeMethod · 0.95
irange_keyMethod · 0.80

Calls 1

iterFunction · 0.50

Tested by

no test coverage detected