def __binary_search(x, fuzzy_sets, ordered_sets):
    """
    Search for elegible fuzzy sets to fuzzyfy x

    :param x: input value to be fuzzyfied
    :param fuzzy_sets:  a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.
    :param ordered_sets: a list with the fuzzy sets names ordered by their centroids.
    :return: A list with the best fuzzy sets that may contain x
    """
    max_len = len(fuzzy_sets) - 1
    first = 0
    last = max_len
    while first <= last:
        midpoint = (first + last) // 2
        fs = ordered_sets[midpoint]
        fs1 = ordered_sets[midpoint - 1] if midpoint > 0 else ordered_sets[0]
        fs2 = ordered_sets[midpoint + 1
            ] if midpoint < max_len else ordered_sets[max_len]
        if fuzzy_sets[fs1].centroid <= fuzzy_sets[fs].transform(x
            ) <= fuzzy_sets[fs2].centroid:
            return midpoint - 1, midpoint, midpoint + 1
        elif midpoint <= 1:
            return [0]
        elif midpoint >= max_len:
            return [max_len]
        elif fuzzy_sets[fs].transform(x) < fuzzy_sets[fs].centroid:
            last = midpoint - 1
        else:
            first = midpoint + 1
