fsspec/utils.py
def merge_offset_ranges(paths, starts, ends, max_gap=0, max_block=None, sort=True):
    """Merge adjacent byte-offset ranges when the inter-range
    gap is <= `max_gap`, and when the merged byte range does not
    exceed `max_block` (if specified). By default, this function
    will re-order the input paths and byte ranges to ensure sorted
    order. If the user can guarantee that the inputs are already
    sorted, passing `sort=False` will skip the re-ordering.
    """

    # Check input
    if not isinstance(paths, list):
        raise TypeError
    if not isinstance(starts, list):
        starts = [starts] * len(paths)
    if not isinstance(ends, list):
        ends = [starts] * len(paths)
    if len(starts) != len(paths) or len(ends) != len(paths):
        raise ValueError

    # Sort by paths and then ranges if `sort=True`
    if sort:
        paths, starts, ends = [list(v) for v in zip(*sorted(zip(paths, starts, ends)))]

    if paths:
        # Loop through the coupled `paths`, `starts`, and
        # `ends`, and merge adjacent blocks when appropriate
        new_paths = paths[:1]
        new_starts = starts[:1]
        new_ends = ends[:1]
        for i in range(1, len(paths)):
            if (
                paths[i] != paths[i - 1]
                or ((starts[i] - new_ends[-1]) > max_gap)
                or ((max_block is not None and (ends[i] - new_starts[-1]) > max_block))
            ):
                # Cannot merge with previous block.
                # Add new `paths`, `starts`, and `ends` elements
                new_paths.append(paths[i])
                new_starts.append(starts[i])
                new_ends.append(ends[i])
            else:
                # Merge with previous block by updating the
                # last element of `ends`
                new_ends[-1] = ends[i]
        return new_paths, new_starts, new_ends

    # `paths` is empty. Just return input lists
    return paths, starts, ends
Merge adjacent byte-offset ranges when the inter-range
    gap is <= `max_gap`, and when the merged byte range does not
    exceed `max_block` (if specified). By default, this function
    will re-order the input paths and byte ranges to ensure sorted
    order. If the user can guarantee that the inputs are already
    sorted, passing `sort=False` will skip the re-ordering.
    
Merge adjacent byte-offset ranges when the inter-range
gap is <= `max_gap`, and when the merged byte range does not
exceed `max_block` (if specified). By default, this function
will re-order the input paths and byte ranges to ensure sorted
order. If the user can guarantee that the inputs are already
sorted, passing `sort=False` will skip the re-ordering.
Merge adjacent byte - offset ranges when the inter - range gap is < = ` max_gap ` and when the merged byte range does not exceed ` max_block ` ( if specified ) . By default this function will re - order the input paths and byte ranges to ensure sorted order . If the user can guarantee that the inputs are already sorted passing ` sort = False ` will skip the re - ordering .
def merge_offset_ranges(paths, starts, ends, max_gap=0, max_block=None, sort=True):
    if not isinstance(paths, list):
        raise TypeError
    if not isinstance(starts, list):
        starts = [starts] * len(paths)
    if not isinstance(ends, list):
        ends = [starts] * len(paths)
    if len(starts) != len(paths) or len(ends) != len(paths):
        raise ValueError
    if sort:
        paths, starts, ends = [list(v) for v in zip(*sorted(zip(paths, starts, ends)))]
    if paths:
        new_paths = paths[:1]
        new_starts = starts[:1]
        new_ends = ends[:1]
        for i in range(1, len(paths)):
            if (
                paths[i] != paths[i - 1]
                or ((starts[i] - new_ends[-1]) > max_gap)
                or ((max_block is not None and (ends[i] - new_starts[-1]) > max_block))
            ):
                new_paths.append(paths[i])
                new_starts.append(starts[i])
                new_ends.append(ends[i])
            else:
                new_ends[-1] = ends[i]
        return new_paths, new_starts, new_ends
    return paths, starts, ends
def merge_offset_ranges ( paths , starts , ends , max_gap = 0 , max_block = None , sort = True ) : if not isinstance ( paths , list ) : raise TypeError if not isinstance ( starts , list ) : starts = [ starts ] * len ( paths ) if not isinstance ( ends , list ) : ends = [ starts ] * len ( paths ) if len ( starts ) != len ( paths ) or len ( ends ) != len ( paths ) : raise ValueError if sort : paths , starts , ends = [ list ( v ) for v in zip ( * sorted ( zip ( paths , starts , ends ) ) ) ] if paths : new_paths = paths [ : 1 ] new_starts = starts [ : 1 ] new_ends = ends [ : 1 ] for i in range ( 1 , len ( paths ) ) : if ( paths [ i ] != paths [ i - 1 ] or ( ( starts [ i ] - new_ends [ - 1 ] ) > max_gap ) or ( ( max_block is not None and ( ends [ i ] - new_starts [ - 1 ] ) > max_block ) ) ) : new_paths . append ( paths [ i ] ) new_starts . append ( starts [ i ] ) new_ends . append ( ends [ i ] ) else : new_ends [ - 1 ] = ends [ i ] return new_paths , new_starts , new_ends return paths , starts , ends
Merge adjacent byte-offset ranges when the inter-range
gap is <= `max_gap`, and when the merged byte range does not
exceed `max_block` (if specified).
Merge adjacent byte - offset ranges when the inter - range gap is < = ` max_gap ` and when the merged byte range does not exceed ` max_block ` ( if specified ) .
"""Merge adjacent byte-offset ranges when the inter-range
    gap is <= `max_gap`, and when the merged byte range does not
    exceed `max_block` (if specified). By default, this function
    will re-order the input paths and byte ranges to ensure sorted
    order. If the user can guarantee that the inputs are already
    sorted, passing `sort=False` will skip the re-ordering.
    """ # Check input # Sort by paths and then ranges if `sort=True` # Loop through the coupled `paths`, `starts`, and # `ends`, and merge adjacent blocks when appropriate # Cannot merge with previous block. # Add new `paths`, `starts`, and `ends` elements # Merge with previous block by updating the # last element of `ends` # `paths` is empty. Just return input lists
paths
starts
ends
max_gap
max_block
sort