def _read_count_byBin(bins, read_sets):
    """
Utility function to be called by "read_count".

"""
    sample_number = len(read_sets)
    cnts = []
    for bs in bins.values():
        for b in bs:
            cnts.append([0] * sample_number)
    within = [0] * sample_number
    for j, read_set in enumerate(read_sets):
        for ch in bins:
            if ch not in read_set:
                continue
            reads = read_set[ch]
            rightmost = len(reads)
            start = 0
            end = 0
            for b in bins[ch]:
                if start == rightmost:
                    break
                temp = b[0]
                left = start
                right = rightmost
                while left < right:
                    mid = (left + right) // 2
                    if reads[mid] >= temp:
                        right = mid
                    else:
                        left = mid + 1
                start = left
                wi_left = end if end > start else start
                temp = b[1]
                left = wi_left
                right = rightmost
                while left < right:
                    mid = (left + right) // 2
                    if reads[mid] >= temp:
                        right = mid
                    else:
                        left = mid + 1
                end = left
                cnts[b[-1] - 1][j] = end - start
                within[j] = within[j] + end - wi_left
    return cnts, within
