_structures.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. class InfinityType(object):
  6. def __repr__(self):
  7. # type: () -> str
  8. return "Infinity"
  9. def __hash__(self):
  10. # type: () -> int
  11. return hash(repr(self))
  12. def __lt__(self, other):
  13. # type: (object) -> bool
  14. return False
  15. def __le__(self, other):
  16. # type: (object) -> bool
  17. return False
  18. def __eq__(self, other):
  19. # type: (object) -> bool
  20. return isinstance(other, self.__class__)
  21. def __ne__(self, other):
  22. # type: (object) -> bool
  23. return not isinstance(other, self.__class__)
  24. def __gt__(self, other):
  25. # type: (object) -> bool
  26. return True
  27. def __ge__(self, other):
  28. # type: (object) -> bool
  29. return True
  30. def __neg__(self):
  31. # type: (object) -> NegativeInfinityType
  32. return NegativeInfinity
  33. Infinity = InfinityType()
  34. class NegativeInfinityType(object):
  35. def __repr__(self):
  36. # type: () -> str
  37. return "-Infinity"
  38. def __hash__(self):
  39. # type: () -> int
  40. return hash(repr(self))
  41. def __lt__(self, other):
  42. # type: (object) -> bool
  43. return True
  44. def __le__(self, other):
  45. # type: (object) -> bool
  46. return True
  47. def __eq__(self, other):
  48. # type: (object) -> bool
  49. return isinstance(other, self.__class__)
  50. def __ne__(self, other):
  51. # type: (object) -> bool
  52. return not isinstance(other, self.__class__)
  53. def __gt__(self, other):
  54. # type: (object) -> bool
  55. return False
  56. def __ge__(self, other):
  57. # type: (object) -> bool
  58. return False
  59. def __neg__(self):
  60. # type: (object) -> InfinityType
  61. return Infinity
  62. NegativeInfinity = NegativeInfinityType()