_structures.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Infinity(object):
  6. def __repr__(self):
  7. return "Infinity"
  8. def __hash__(self):
  9. return hash(repr(self))
  10. def __lt__(self, other):
  11. return False
  12. def __le__(self, other):
  13. return False
  14. def __eq__(self, other):
  15. return isinstance(other, self.__class__)
  16. def __ne__(self, other):
  17. return not isinstance(other, self.__class__)
  18. def __gt__(self, other):
  19. return True
  20. def __ge__(self, other):
  21. return True
  22. def __neg__(self):
  23. return NegativeInfinity
  24. Infinity = Infinity()
  25. class NegativeInfinity(object):
  26. def __repr__(self):
  27. return "-Infinity"
  28. def __hash__(self):
  29. return hash(repr(self))
  30. def __lt__(self, other):
  31. return True
  32. def __le__(self, other):
  33. return True
  34. def __eq__(self, other):
  35. return isinstance(other, self.__class__)
  36. def __ne__(self, other):
  37. return not isinstance(other, self.__class__)
  38. def __gt__(self, other):
  39. return False
  40. def __ge__(self, other):
  41. return False
  42. def __neg__(self):
  43. return Infinity
  44. NegativeInfinity = NegativeInfinity()