<commit_before>import copy
from sets import Set
from .exceptions import TwoPhaseSetException

class TwoPhaseSet(object):
    """
     Set where an element may be added and removed, but never added again thereafter.
     Adding or removing the same element twice has no effect, nor does adding an element
     that has already been removed.
    """

    def __init__(self):
        self.a = Set()
        self.r = Set()

    def add(self, element):
        self.a.add(element)

    def remove(self, element):
        if element in self.a:
            self.r.add(element)
        else:
            raise TwoPhaseSetException('Attempted to delete non-existing element.')

    def lookup(self, element):
        return element in (self.a - self.r)

    def merge(self, other):
        if not isinstance(other, self.__class__):
            raise TwoPhaseSetException('Attempted to merge with different type.')
        self.a.union_update(other.a)
        self.r.union_update(other.r)

    def clone(self):
        return copy.deepcopy(self)

    def to_list(self):
        return list(self.a - self.r)<commit_msg>Add repr to 2p-Set.<commit_after>import copy
import json
from sets import Set
from .exceptions import TwoPhaseSetException

class TwoPhaseSet(object):
    """
     Set where an element may be added and removed, but never added again thereafter.
     Adding or removing the same element twice has no effect, nor does adding an element
     that has already been removed.
    """

    def __init__(self):
        self.a = Set()
        self.r = Set()

    def add(self, element):
        self.a.add(element)

    def remove(self, element):
        if element in self.a:
            self.r.add(element)
        else:
            raise TwoPhaseSetException('Attempted to delete non-existing element.')

    def lookup(self, element):
        return element in (self.a - self.r)

    def merge(self, other):
        if not isinstance(other, self.__class__):
            raise TwoPhaseSetException('Attempted to merge with different type.')
        self.a.union_update(other.a)
        self.r.union_update(other.r)

    def clone(self):
        return copy.deepcopy(self)

    def to_list(self):
        return list(self.a - self.r)

    def __repr__(self):
        return json.dumps({
            'type': '2p-set',
            'a': list(self.a),
            'r': list(self.r)
        })
{'fraction_non_alphanumeric': 0.09627459187944747, 'fraction_numerical': 0.0008371703641691084, 'mean_word_length': 2.328690807799443, 'pattern_counts': {'":': 0, '<': 3, '<?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': '771045', 'n_tokens_mistral': 700, 'n_tokens_neox': 673, 'n_words': 222}