_structures.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright 2014 Donald Stufft
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import absolute_import, division, print_function
  15. class Infinity(object):
  16. def __repr__(self):
  17. return "Infinity"
  18. def __hash__(self):
  19. return hash(repr(self))
  20. def __lt__(self, other):
  21. return False
  22. def __le__(self, other):
  23. return False
  24. def __eq__(self, other):
  25. return isinstance(other, self.__class__)
  26. def __ne__(self, other):
  27. return not isinstance(other, self.__class__)
  28. def __gt__(self, other):
  29. return True
  30. def __ge__(self, other):
  31. return True
  32. def __neg__(self):
  33. return NegativeInfinity
  34. Infinity = Infinity()
  35. class NegativeInfinity(object):
  36. def __repr__(self):
  37. return "-Infinity"
  38. def __hash__(self):
  39. return hash(repr(self))
  40. def __lt__(self, other):
  41. return True
  42. def __le__(self, other):
  43. return True
  44. def __eq__(self, other):
  45. return isinstance(other, self.__class__)
  46. def __ne__(self, other):
  47. return not isinstance(other, self.__class__)
  48. def __gt__(self, other):
  49. return False
  50. def __ge__(self, other):
  51. return False
  52. def __neg__(self):
  53. return Infinity
  54. NegativeInfinity = NegativeInfinity()