<commit_before>__all__ = [
    'TransitionPair', 'TransitionFunction',
    'indicator', 'merge'
];

class TransitionPair(object):
    def __init__(self, terminal, value):
        self.terminal = terminal;
        self.value = value;

    def __eq__(self, right):
        return self.terminal == right.terminal and self.value == right.value;

    def __lt__(self, right):
        if self.terminal < right.terminal: return True;
        if right.terminal < self.terminal: return False;

        return self.value < right.value;

    def __le__(self, right):
        if self.terminal < right.terminal: return True;
        if right.terminal < self.terminal: return False;

        return self.value <= right.value;

    def __repr__(self):
        return 'TransitionPair(%i, %s)' % (self.terminal, repr(self.value));

    def __str__(self):
        return '(%i, %s)' % (self.terminal, str(self.value));

class TransitionFunction(object):
    undef = object();

    def __init__(self, definition):
        self.definition = sorted(definition);

    def __call__(self, terminal):
        d = self.definition;
        low, high = 0, len(d);

        while low < high:
            mid = (low + high) / 2;
            if d[mid].terminal < terminal: low = mid + 1;
            else: high = mid;

        return d[low].value if 0 <= low < len(d) else self.undef;

    def __eq__(self, other):
        return self.definition == other.definition;

    def __repr__(self):
        return 'TransitionFunction(%s)' % str(self.definition);

    def __str__(self):
        return 'TransitionFunction([%s])' % ', '.join(map(str, self.definition));

    def compact(self):
        return TransitionFunction(self.__compact());

    @classmethod
    def from_items(cls, items):
        return cls(TransitionPair(*p) for p in items);

    def transform(self, xform):
        return TransitionFunction(TransitionPair(p.token, xform(p.value)) for p in self.definition);
<commit_msg>- Fix to TransitionFunction equality function<commit_after>__all__ = [
    'TransitionPair', 'TransitionFunction',
    'indicator', 'merge'
];

class TransitionPair(object):
    def __init__(self, terminal, value):
        self.terminal = terminal;
        self.value = value;

    def __eq__(self, right):
        return self.terminal == right.terminal and self.value == right.value;

    def __lt__(self, right):
        if self.terminal < right.terminal: return True;
        if right.terminal < self.terminal: return False;

        return self.value < right.value;

    def __le__(self, right):
        if self.terminal < right.terminal: return True;
        if right.terminal < self.terminal: return False;

        return self.value <= right.value;

    def __repr__(self):
        return 'TransitionPair(%i, %s)' % (self.terminal, repr(self.value));

    def __str__(self):
        return '(%i, %s)' % (self.terminal, str(self.value));

class TransitionFunction(object):
    undef = object();

    def __init__(self, definition):
        self.definition = sorted(definition);

    def __call__(self, terminal):
        d = self.definition;
        low, high = 0, len(d);

        while low < high:
            mid = (low + high) / 2;
            if d[mid].terminal < terminal: low = mid + 1;
            else: high = mid;

        return d[low].value if 0 <= low < len(d) else self.undef;

    def __eq__(self, other):
        return type(other) == TransitionFunction and self.definition == other.definition;

    def __repr__(self):
        return 'TransitionFunction(%s)' % str(self.definition);

    def __str__(self):
        return 'TransitionFunction([%s])' % ', '.join(map(str, self.definition));

    def compact(self):
        return TransitionFunction(self.__compact());

    @classmethod
    def from_items(cls, items):
        return cls(TransitionPair(*p) for p in items);

    def transform(self, xform):
        return TransitionFunction(TransitionPair(p.token, xform(p.value)) for p in self.definition);

{'fraction_non_alphanumeric': 0.13020572002007025, 'fraction_numerical': 0.002007024586051179, 'mean_word_length': 2.750705550329257, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4719904', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1123, 'n_words': 314}