<commit_before># -*- coding: utf-8 -*-
# ordered_set_queue.py: Thread-safe implementation of an ordered set queue.
#
# Implementation from:
# --------------------
# http://stackoverflow.com/questions/1581895/how-check-if-a-task-is-already-in-python-queue

"""
    Thread-safe implementation of an ordered set queue.

    :module: watchdog.utils.collection.ordered_set_queue
    :author: <NAME> <<EMAIL>>
    :author: <NAME> <<EMAIL>>
"""


try:
    import queue
except ImportError:
    import Queue as queue


class OrderedSetQueue(queue.Queue):
    """Thread-safe implementation of an ordered set queue.

    Disallows adding a duplicate item while maintaining the
    order of items in the queue. The implementation leverages
    locking already implemented in the Python Queue class
    redefining only the primitives. Since the internal queue
    is not replaced, the order is maintained. The set is used
    merely to check for the existence of an item.

    Queued items must be immutable and hashable so that they can be used
    as dictionary keys. You must implement **only read-only properties** and
    the :func:`__hash__()`, :func:`__eq__()`, and :func:`__ne__` methods 
    for items to be hashable. An example implementation follows::
    
        class Item(object):
            def __init__(self, a, b):
                self._a = a
                self._b = b
            
            @property
            def a(self):
                return self._a
                
            @property
            def b(self):
                return self._b
    
            def _key(self):
                return (self._a, self._b)
    
            def __eq__(self, item):
                return self._key() == item._key()
            
            def __ne__(self, item):
                return self._key() != item._key()
            
            def __hash__(self):
                return hash(self._key())
    """
    def _init(self, maxsize):
        queue.Queue._init(self, maxsize)
        self._set_of_items = set()

    def _put(self, item):
        if item not in self._set_of_items:
            queue.Queue._put(self, item)
            self._set_of_items.add(item)

    def _get(self):
        item = queue.Queue._get(self)
        self._set_of_items.remove(item)
        return item<commit_msg>Moving ordered set queue to collections.<commit_after># -*- coding: utf-8 -*-
# ordered_set_queue.py: Thread-safe implementation of an ordered set queue.
{'fraction_non_alphanumeric': 0.1027202598457166, 'fraction_numerical': 0.0036540803897685747, 'mean_word_length': 2.038224414303329, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7383999', 'n_tokens_mistral': 694, 'n_tokens_neox': 667, 'n_words': 219}