# Path: pyalgs/algorithms/commons/util.py
# def less(a, b):
# def greater(a, b):
# def cmp(a, b):
# def exchange(a, i, j):
# def is_sorted(a):


from pyalgs.algorithms.commons import util
    @staticmethod
    def char_at(text, d):
        if len(text) <= d + 1:
            return -1
        return ord(text[d])


class String3WayQuickSort(object):
    @staticmethod
    def sort(a):
        String3WayQuickSort._sort(a, 0, len(a) - 1, 0)

    @staticmethod
    def _sort(a, lo, hi, d):
        if lo >= hi:
            return

        lt = lo
        i = lo
        gt = hi

        c = String3WayQuickSort.char_at(a[lo], d)

        while i < gt:
            cmp = c - String3WayQuickSort.char_at(a[i], d)
            if cmp > 0:
                util.exchange(a, i, lt)
                i += 1
                lt += 1
            elif cmp < 0:

# Path: pyalgs/algorithms/commons/util.py
# def less(a, b):
# def greater(a, b):
# def cmp(a, b):
# def exchange(a, i, j):
# def is_sorted(a):


# Path: pyalgs/algorithms/strings/sorting.py
from pyalgs.algorithms.commons import util

    @staticmethod
    def char_at(text, d):
        if len(text) <= d + 1:
            return -1
        return ord(text[d])


class String3WayQuickSort(object):
    @staticmethod
    def sort(a):
        String3WayQuickSort._sort(a, 0, len(a) - 1, 0)

    @staticmethod
    def _sort(a, lo, hi, d):
        if lo >= hi:
            return

        lt = lo
        i = lo
        gt = hi

        c = String3WayQuickSort.char_at(a[lo], d)

        while i < gt:
            cmp = c - String3WayQuickSort.char_at(a[i], d)
            if cmp > 0:
                util.exchange(a, i, lt)
                i += 1
                lt += 1
            elif cmp < 0:

                util.exchange(a, i, gt)