def _bytearray_comparator(a, b):
    """Implements a comparator using the lexicographical ordering of octets as unsigned integers."""
    a_len = len(a)
    b_len = len(b)
    i = 0
    while i < a_len and i < b_len:
        a_byte = a[i]
        b_byte = b[i]
        if a_byte != b_byte:
            if a_byte - b_byte < 0:
                return -1
            else:
                return 1
        i += 1
    len_diff = a_len - b_len
    if len_diff < 0:
        return -1
    elif len_diff > 0:
        return 1
    else:
        return 0
