# -*- coding: utf-8 -*- from collections import KeysView, ValuesView, ItemsView from itertools import izip try: from compat import make_sentinel _MISSING = make_sentinel(var_name='_MISSING') except ImportError: _MISSING = object() PREV, NEXT, KEY, VALUE, SPREV, SNEXT = range(6) __all__ = ['MultiDict', 'OrderedMultiDict'] try: profile except NameError: profile = lambda x: x class OrderedMultiDict(dict): """\ A MultiDict that remembers original insertion order. A MultiDict is a dictionary that can have multiple values per key, most commonly useful for handling parsed query strings and inverting dictionaries to create a reverse index. >>> omd = OrderedMultiDict()
The OMD has been performance tuned to be suitable for a wide range of usages, including as a basic unordered MultiDict. Special thanks to `Mark Williams`_ for all his help. .. [1] As of 2015, `basic dicts on PyPy are ordered <http://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html>`_. .. _Mark Williams: https://github.com/markrwilliams """ from itertools import izip from collections import KeysView, ValuesView, ItemsView try: from compat import make_sentinel _MISSING = make_sentinel(var_name='_MISSING') except ImportError: _MISSING = object() PREV, NEXT, KEY, VALUE, SPREV, SNEXT = range(6) __all__ = ['MultiDict', 'OMD', 'OrderedMultiDict'] try: profile except NameError: profile = lambda x: x class OrderedMultiDict(dict): """A MultiDict is a dictionary that can have multiple values per key
from _thread import RLock except: class RLock(object): 'Dummy reentrant lock for builds without threads' def __enter__(self): pass def __exit__(self, exctype, excinst, exctb): pass try: from compat import make_sentinel _MISSING = make_sentinel(var_name='_MISSING') _KWARG_MARK = make_sentinel(var_name='_KWARG_MARK') except ImportError: _MISSING = object() _KWARG_MARK = object() PREV, NEXT, KEY, VALUE = range(4) # names for the link fields DEFAULT_MAX_SIZE = 128 class LRU(dict): """The ``LRU`` is :class:`dict` subtype implementation of the *Least-Recently Used* caching strategy. Args: max_size (int): Max number of items to cache. Defaults to ``128``.
4 >>> pq.pop() 'high priority task' >>> pq.peek() 'medium priority task 1' >>> len(pq) 3 """ from heapq import heappush, heappop from bisect import insort import itertools try: from compat import make_sentinel _REMOVED = make_sentinel(var_name='_REMOVED') except ImportError: _REMOVED = object() try: from listutils import BList # see BarrelList docstring for notes except ImportError: BList = list __all__ = [ 'PriorityQueue', 'BasePriorityQueue', 'HeapPriorityQueue', 'SortedPriorityQueue' ] # TODO: make Base a real abstract class
from collections import deque try: from _thread import RLock except: class RLock(object): 'Dummy reentrant lock for builds without threads' def __enter__(self): pass def __exit__(self, exctype, excinst, exctb): pass try: from compat import make_sentinel _MISSING = make_sentinel(var_name='_MISSING') _KWARG_MARK = make_sentinel(var_name='_KWARG_MARK') except ImportError: _MISSING = object() _KWARG_MARK = object() PREV, NEXT, KEY, VALUE = range(4) # names for the link fields DEFAULT_MAX_SIZE = 128 class LRU(dict): """The ``LRU`` is :class:`dict` subtype implementation of the *Least-Recently Used* caching strategy. Args:
>>> pq.pop() 'high priority task' >>> pq.peek() 'medium priority task 1' >>> len(pq) 3 """ from heapq import heappush, heappop from bisect import insort import itertools try: from compat import make_sentinel _REMOVED = make_sentinel(var_name='_REMOVED') except ImportError: _REMOVED = object() try: from listutils import BList # see BarrelList docstring for notes except ImportError: BList = list __all__ = ['PriorityQueue', 'BasePriorityQueue', 'HeapPriorityQueue', 'SortedPriorityQueue'] # TODO: make Base a real abstract class
# -*- coding: utf-8 -*- from bisect import bisect_left from itertools import chain, islice from collections import MutableSet import operator try: from compat import make_sentinel _MISSING = make_sentinel(var_name="_MISSING") except ImportError: _MISSING = object() __all__ = ["IndexedSet"] _COMPACTION_FACTOR = 8 # TODO: inherit from set() # TODO: .discard_many(), .remove_many() # TODO: raise exception on non-set params? # TODO: technically reverse operators should probably reverse the # order of the 'other' inputs and put self last (to try and maintain # insertion order) class IndexedSet(MutableSet): """\ IndexedSet maintains insertion order and uniqueness of inserted