polytracker.cache¶
cache classes¶
LRUCache¶
- class polytracker.cache.LRUCache(max_size: Optional[int] = 30000000)¶
Bases:
Generic
[R
,V
],MutableMapping
- classmethod __class_getitem__(params)¶
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- clear() None. Remove all items from D. ¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶
Memoized¶
- class polytracker.cache.Memoized(func: Callable[[...], R])¶
Bases:
Generic
[R
]- classmethod __class_getitem__(params)¶
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
OrderedSet¶
- class polytracker.cache.OrderedSet(*items: R)¶
Bases:
Generic
[R
],MutableSet
- classmethod __class_getitem__(params)¶
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- __init__(*items: R)¶
- classmethod _from_iterable(it)¶
Construct an instance of the class from any iterable input.
Must override this method if the class constructor signature does not accept an iterable for an input.
- _hash()¶
Compute the hash value of a set.
Note that we don’t define __hash__: not all sets are hashable. But if you define a hashable set type, its __hash__ should call this function.
This must be compatible __eq__.
All sets ought to compare equal if they contain the same elements, regardless of how they are implemented, and regardless of the order of the elements; so there’s not much freedom for __eq__ or __hash__. We match the algorithm used by the built-in frozenset type.
- add(item: R)¶
Add an element.
- clear()¶
This is slow (creates N new iterators!) but effective.
- discard(item: R)¶
Remove an element. Do not raise an exception if absent.
- isdisjoint(other)¶
Return True if two sets have a null intersection.
- pop()¶
Return the popped value. Raise KeyError if empty.
- remove(value)¶
Remove an element. If not a member, raise a KeyError.