def new_rangesplitter()

in dataflux_core/range_splitter.py [0:0]


def new_rangesplitter(alphabet: str) -> RangeSplitter:
    """Creates a new RangeSplitter with the given alphabets.

    Note that the alphabets are a predetermined set of characters
    by the work-stealing algorithm, and the characters are guaranteed to be unique.

    Args:
      alphabet (str): The full set of characters used for this range splitter.

    Returns:
      An instance of the RangeSplitter class that is used to manage splits
      performed to facilitate the work-stealing algorithm.
    """
    if len(alphabet) == 0:
        raise ValueError("Cannot split with an empty alphabet.")
    sorted_alphabet = sorted(alphabet)
    alphabet_map = {val: index for index, val in enumerate(sorted_alphabet)}
    return RangeSplitter(alphabet_map, sorted_alphabet)