X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ad69b48e324c3ce29a4d2c84732dfd3d0288ebb3..fd0074f2200bc41bc63be770fffbe2446fb0cc03:/sdk/python/arvados/_ranges.py diff --git a/sdk/python/arvados/_ranges.py b/sdk/python/arvados/_ranges.py index 15f01735e0..947b35fe0f 100644 --- a/sdk/python/arvados/_ranges.py +++ b/sdk/python/arvados/_ranges.py @@ -10,7 +10,7 @@ class Range(object): self.segment_offset = segment_offset def __repr__(self): - return "Range(\"%s\", %i, %i, %i)" % (self.locator, self.range_start, self.range_size, self.segment_offset) + return "Range(%r, %r, %r, %r)" % (self.locator, self.range_start, self.range_size, self.segment_offset) def __eq__(self, other): return (self.locator == other.locator and @@ -32,7 +32,7 @@ def first_block(data_locators, range_start, range_size): block_end = block_start + block_size # perform a binary search for the first block - # assumes that all of the blocks are contigious, so range_start is guaranteed + # assumes that all of the blocks are contiguous, so range_start is guaranteed # to either fall into the range of a block or be outside the block range entirely while not (range_start >= block_start and range_start < block_end): if lo == i: @@ -63,14 +63,15 @@ class LocatorAndRange(object): self.segment_size == other.segment_size) def __repr__(self): - return "LocatorAndRange(\"%s\", %i, %i, %i)" % (self.locator, self.block_size, self.segment_offset, self.segment_size) + return "LocatorAndRange(%r, %r, %r, %r)" % (self.locator, self.block_size, self.segment_offset, self.segment_size) def locators_and_ranges(data_locators, range_start, range_size): - """Get blocks that are covered by the range and return list of LocatorAndRange - objects. + """Get blocks that are covered by a range. + + Returns a list of LocatorAndRange objects. :data_locators: - list of Range objects, assumes that blocks are in order and contigous + list of Range objects, assumes that blocks are in order and contiguous :range_start: start of range @@ -82,14 +83,14 @@ def locators_and_ranges(data_locators, range_start, range_size): if range_size == 0: return [] resp = [] - range_start = range_start - range_size = range_size range_end = range_start + range_size i = first_block(data_locators, range_start, range_size) if i is None: return [] + # We should always start at the first segment due to the binary + # search. while i < len(data_locators): dl = data_locators[i] block_start = dl.range_start @@ -100,13 +101,6 @@ def locators_and_ranges(data_locators, range_start, range_size): # range ends before this block starts, so don't look at any more locators break - #if range_start >= block_end: - # Range starts after this block ends, so go to next block. - # We should always start at the first block due to the binary - # search above, so this test is unnecessary but useful to help - # document the algorithm. - #next - if range_start >= block_start and range_end <= block_end: # range starts and ends in this block resp.append(LocatorAndRange(dl.locator, block_size, dl.segment_offset + (range_start - block_start), range_size)) @@ -131,7 +125,7 @@ def replace_range(data_locators, new_range_start, new_range_size, new_locator, n data_locators will be updated in place :data_locators: - list of Range objects, assumes that segments are in order and contigous + list of Range objects, assumes that segments are in order and contiguous :new_range_start: start of range to replace in data_locators @@ -149,8 +143,6 @@ def replace_range(data_locators, new_range_start, new_range_size, new_locator, n if new_range_size == 0: return - new_range_start = new_range_start - new_range_size = new_range_size new_range_end = new_range_start + new_range_size if len(data_locators) == 0: @@ -170,6 +162,8 @@ def replace_range(data_locators, new_range_start, new_range_size, new_locator, n if i is None: return + # We should always start at the first segment due to the binary + # search. while i < len(data_locators): dl = data_locators[i] old_segment_start = dl.range_start @@ -179,13 +173,6 @@ def replace_range(data_locators, new_range_start, new_range_size, new_locator, n # range ends before this segment starts, so don't look at any more locators break - #if range_start >= old_segment_end: - # Range starts after this segment ends, so go to next segment. - # We should always start at the first segment due to the binary - # search above, so this test is unnecessary but useful to help - # document the algorithm. - #next - if old_segment_start <= new_range_start and new_range_end <= old_segment_end: # new range starts and ends in old segment # split segment into up to 3 pieces