<commit_before>import threading
import BinPy
import networkx as nx
import time


class AutoUpdater(threading.Thread):

    _graph = nx.DiGraph()
    
    @staticmethod
    def add_link(a, b):
        AutoUpdater._graph.add_edge(a, b)

    @staticmethod
    def remove_link(a, b):
        AutoUpdater._graph.remove_edge(a, b)
    
    def __init__(self):
        threading.Thread.__init__(self) 

        self.daemon = True
        self.start()

    def run(self):
        while True:
            nodes = AutoUpdater._graph.nodes()

            for i in nodes:
                for pair in AutoUpdater._graph.edges(i):
                    pair[1].set_voltage(pair[0])
                    # Copies the value of the 0th index connector to the 1st
                    # index connector
                    
                    time.sleep(0.01)

            # One circuit has been traversed.


# Initiating the auto updater.
#auto_updater_instance = AutoUpdater()


class BinPyIndexer(object):

    _indices = {}     # { gates.AND : { 1:<AND instance> } }
    _rev_indices = {}  # { gates.AND : { <AND instance>:1 } }

    _max_index = {}   # { gates.AND : 1 }

    @staticmethod
    @property
    def indices():
        return BinPyIndexer._indices

    @staticmethod
    @property
    def indices():
        return BinPyIndexer._rev_indices

    @staticmethod
    def index(element):
        """ Add an element to the indexed list and return its unique ID """
        if element.__class__ not in BinPyIndexer._indices:
            BinPyIndexer._indices[element.__class__] = {}
            BinPyIndexer._rev_indices[element.__class__] = {}
            BinPyIndexer._max_index[element.__class__] = 0

        if BinPyIndexer.get_index(element) is not None:
            return BinPyIndexer.get_index(element)

        # Unique ID numbers are not recycled.
        BinPyIndexer._max_index[element.__class__] += 1

        # Unique ID for the element
        uid = BinPyIndexer._max_index[element.__class__]

        BinPyIndexer._indices[element.__class__][
            uid] = element       # UniqueID:element

        BinPyIndexer._rev_indices[element.__class__][
            element] = uid   # element:UniqueID

        return uid

    @staticmethod
    def unindex(element=None, index=None, cls=None):
        if (element, index, cls) == (None, None, None):
            raise Exception("Specify atleast one parameter")

        if element is not None:
            index = BinPyIndexer.get_index(element)
            cls = element.__class__

        if (index, cls) == (None, None):
            raise Exception("Insufficient parameters passed")

        BinPyIndexer._indices[element.__class__].pop(index)
        BinPyIndexer._rev_indices[element.__class__].pop(element)

    @staticmethod
    def get_index(element):
        """ Get the index of the element """
        if element in BinPyIndexer._rev_indices[element.__class__]:
            return BinPyIndexer._rev_indices[element.__class__][element]

    @staticmethod
    def get_element(index, cls):
        """
        Get the element of the specified index and class

        USAGE:
        ======
        >>> g1 = AND(1,0)
        >>> BinPyIndexer.get_element(g1, AND)
        1

        """
        if (cls in BinPyIndexer._indices) and (index in BinPyIndexer._indices[cls]):
            return BinPyIndexer._indices[cls][index]<commit_msg>Bus Support Added<commit_after>import threading
import BinPy
import networkx as nx
import time


class AutoUpdater(threading.Thread):

    _graph = nx.DiGraph()

    @staticmethod
    def add_link(a, b, directed = True):
        """
        Link a list of Connectors ( or  a Bus of connectors ) with another list / Bus for auto-updation.
        """

        if ( type(a), type(b) ) == ( list, list ):
            if len(a) != len(b):
                raise Exception("ERROR: Lengths are not equal")
            for i, j in zip(a,b):
                if ( isinstance(i, Connector) , isinstance(j, Connector) ) != ( True, True ):
                    raise Exception("ERROR: Only Connector objects can be linked")
                if not AutoUpdater._graph.has_edge(i, j):
                    AutoUpdater._graph.add_edge(i, j)

                    if ( not directed ) and ( not AutoUpdater._graph.has_edge(j, i)):
                       AutoUpdater._graph.add_edge(j, i)
        else:
            raise Exception("Invalid Input")
     
    @staticmethod
    def remove_link(a, b, directed = True):
        """
        Unlink a list of Connectors ( or  a Bus of connectors ) with another list / Bus.
        """

        if ( type(a), type(b) ) == ( list, list ):
            if len(a) != len(b):
                raise Exception("ERROR: Lengths are not equal")
            for i, j in zip(a,b):
                if ( isinstance(i, Connector) , isinstance(j, Connector) ) != ( True, True ):
                    raise Exception("ERROR: Only Connector objects can be linked")
                if AutoUpdater._graph.has_edge(i, j):
                    AutoUpdater._graph.remove_edge(i, j)

                    if not directed and AutoUpdater._graph.has_edge(j, i):
                        AutoUpdater._graph.remove_edge(j, i)

        else:
            raise Exception("Invalid Input")

    def __init__(self):
        threading.Thread.__init__(self)

        self.daemon = True
        self.start()

    def run(self):
        while True:
            nodes = AutoUpdater._graph.nodes()

            for i in nodes:
                for pair in AutoUpdater._graph.edges(i):
                    pair[1].set_voltage(pair[0])
                    # Copies the value of the 0th index connector to the 1st
                    # index connector

                    time.sleep(0.01)

            # One circuit has been traversed.


# Initiating the auto updater.
#auto_updater_instance = AutoUpdater()


class BinPyIndexer(object):

    _indices = {}     # { gates.AND : { 1:<AND instance> } }
    _rev_indices = {}  # { gates.AND : { <AND instance>:1 } }

    _max_index = {}   # { gates.AND : 1 }

    @staticmethod
    @property
    def indices():
        return BinPyIndexer._indices

    @staticmethod
    @property
    def indices():
        return BinPyIndexer._rev_indices

    @staticmethod
    def index(element):
        """ Add an element to the indexed list and return its unique ID """
        if element.__class__ not in BinPyIndexer._indices:
            BinPyIndexer._indices[element.__class__] = {}
            BinPyIndexer._rev_indices[element.__class__] = {}
            BinPyIndexer._max_index[element.__class__] = 0

        if BinPyIndexer.get_index(element) is not None:
            return BinPyIndexer.get_index(element)

        # Unique ID numbers are not recycled.
        BinPyIndexer._max_index[element.__class__] += 1

        # Unique ID for the element
        uid = BinPyIndexer._max_index[element.__class__]

        BinPyIndexer._indices[element.__class__][
            uid] = element       # UniqueID:element

        BinPyIndexer._rev_indices[element.__class__][
            element] = uid   # element:UniqueID

        return uid

    @staticmethod
    def unindex(element=None, index=None, cls=None):
        if (element, index, cls) == (None, None, None):
            raise Exception("Specify atleast one parameter")

        if element is not None:
            index = BinPyIndexer.get_index(element)
            cls = element.__class__

        if (index, cls) == (None, None):
            raise Exception("Insufficient parameters passed")

        BinPyIndexer._indices[element.__class__].pop(index)
        BinPyIndexer._rev_indices[element.__class__].pop(element)

    @staticmethod
    def get_index(element):
        """ Get the index of the element """
        if element in BinPyIndexer._rev_indices[element.__class__]:
            return BinPyIndexer._rev_indices[element.__class__][element]

    @staticmethod
    def get_element(index, cls):
        """
        Get the element of the specified index and class

        USAGE:
        ======

        >>> g1 = AND(1,0)
        >>> BinPyIndexer.get_element(g1, AND)
        1

        """
        if (cls in BinPyIndexer._indices) and (index in BinPyIndexer._indices[cls]):
            return BinPyIndexer._indices[cls][index]
{'fraction_non_alphanumeric': 0.09887992291942671, 'fraction_numerical': 0.004094905455859328, 'mean_word_length': 2.055187637969095, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '3797290', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2341, 'n_words': 603}