|
17 | 17 | import threading |
18 | 18 | import contextlib |
19 | 19 | import json |
20 | | -import typing as _tp |
21 | 20 | from pprint import pformat |
22 | 21 |
|
23 | 22 | from types import ModuleType |
|
35 | 34 |
|
36 | 35 | from numba.cuda.core import config |
37 | 36 |
|
38 | | -from collections.abc import Mapping, Sequence, MutableSet, MutableMapping |
| 37 | +from collections.abc import Sequence |
39 | 38 |
|
40 | 39 | PYVERSION = config.PYVERSION |
41 | 40 |
|
@@ -354,102 +353,6 @@ def key(x): |
354 | 353 | return order |
355 | 354 |
|
356 | 355 |
|
357 | | -T = _tp.TypeVar("T") |
358 | | - |
359 | | - |
360 | | -class OrderedSet(MutableSet[T]): |
361 | | - def __init__(self, iterable: _tp.Iterable[T] = ()): |
362 | | - # Just uses a dictionary under-the-hood to maintain insertion order. |
363 | | - self._data = dict.fromkeys(iterable, None) |
364 | | - |
365 | | - def __contains__(self, key): |
366 | | - return key in self._data |
367 | | - |
368 | | - def __iter__(self): |
369 | | - return iter(self._data) |
370 | | - |
371 | | - def __len__(self): |
372 | | - return len(self._data) |
373 | | - |
374 | | - def add(self, item): |
375 | | - self._data[item] = None |
376 | | - |
377 | | - def discard(self, item): |
378 | | - self._data.pop(item, None) |
379 | | - |
380 | | - |
381 | | -class MutableSortedSet(MutableSet[T], _tp.Generic[T]): |
382 | | - """Mutable Sorted Set""" |
383 | | - |
384 | | - def __init__(self, values: _tp.Iterable[T] = ()): |
385 | | - self._values = set(values) |
386 | | - |
387 | | - def __len__(self): |
388 | | - return len(self._values) |
389 | | - |
390 | | - def __iter__(self): |
391 | | - return iter(k for k in sorted(self._values)) |
392 | | - |
393 | | - def __contains__(self, x: T) -> bool: |
394 | | - return self._values.__contains__(x) |
395 | | - |
396 | | - def add(self, x: T): |
397 | | - return self._values.add(x) |
398 | | - |
399 | | - def discard(self, value: T): |
400 | | - self._values.discard(value) |
401 | | - |
402 | | - def update(self, values): |
403 | | - self._values.update(values) |
404 | | - |
405 | | - |
406 | | -Tk = _tp.TypeVar("Tk") |
407 | | -Tv = _tp.TypeVar("Tv") |
408 | | - |
409 | | - |
410 | | -class SortedMap(Mapping[Tk, Tv], _tp.Generic[Tk, Tv]): |
411 | | - """Immutable""" |
412 | | - |
413 | | - def __init__(self, seq): |
414 | | - self._values = [] |
415 | | - self._index = {} |
416 | | - for i, (k, v) in enumerate(sorted(seq)): |
417 | | - self._index[k] = i |
418 | | - self._values.append((k, v)) |
419 | | - |
420 | | - def __getitem__(self, k): |
421 | | - i = self._index[k] |
422 | | - return self._values[i][1] |
423 | | - |
424 | | - def __len__(self): |
425 | | - return len(self._values) |
426 | | - |
427 | | - def __iter__(self): |
428 | | - return iter(k for k, v in self._values) |
429 | | - |
430 | | - |
431 | | -class MutableSortedMap(MutableMapping[Tk, Tv], _tp.Generic[Tk, Tv]): |
432 | | - def __init__(self, dct=None): |
433 | | - if dct is None: |
434 | | - dct = {} |
435 | | - self._dct: dict[Tk, Tv] = dct |
436 | | - |
437 | | - def __getitem__(self, k: Tk) -> Tv: |
438 | | - return self._dct[k] |
439 | | - |
440 | | - def __setitem__(self, k: Tk, v: Tv): |
441 | | - self._dct[k] = v |
442 | | - |
443 | | - def __delitem__(self, k: Tk): |
444 | | - del self._dct[k] |
445 | | - |
446 | | - def __len__(self) -> int: |
447 | | - return len(self._dct) |
448 | | - |
449 | | - def __iter__(self) -> int: |
450 | | - return iter(k for k in sorted(self._dct)) |
451 | | - |
452 | | - |
453 | 356 | class UniqueDict(dict): |
454 | 357 | def __setitem__(self, key, value): |
455 | 358 | if key in self: |
|
0 commit comments