Skip to content
Snippets Groups Projects
Commit e3ad397d authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

add iterate_range

parent f580a546
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ cdef class Chunk:
readonly bint writable
object write_lock
cpdef object iterate_range(self, unsigned long starting_entry, unsigned long stopping_entry)
cpdef void close(self)
cpdef tuple get_piece_at(self, unsigned int index)
cpdef int put(self, unsigned long long timestamp, bytes data) except -1
......
......@@ -85,6 +85,24 @@ cdef class Chunk:
self.max_ts = timestamp
return 0
cpdef object iterate_range(self, unsigned long starting_entry, unsigned long stopping_entry):
"""
Return a partial iterator starting at starting_entry and ending at stopping_entry (exclusive)
:param starting_entry: number of starting entry
:type starting_entry: int
:param stopping_entry: number of stopping entry
:type stopping_entry:
:return: an iterator
:rtype: tp.Iterator[tp.Tuple[int, bytes]]
"""
return self._iterate(starting_entry, stopping_entry)
def _iterate(self, starting_entry: int, stopping_entry: int):
cdef int i
for i in range(starting_entry, stopping_entry):
yield self.get_piece_at(i)
def __iter__(self) -> tp.Iterator[tp.Tuple[int, bytes]]:
cdef unsigned long i = 0
for i in range(self.entries):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment