Interval.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "CommonDataStructuresPch.h"
  6. #include "DataStructures/Interval.h"
  7. namespace regex
  8. {
  9. bool Interval::Includes(int value) const
  10. {
  11. return (begin <= value) && (end >= value);
  12. }
  13. bool Interval::Includes(Interval other) const
  14. {
  15. return (Includes(other.Begin()) && (Includes(other.End())));
  16. }
  17. int Interval::CompareTo(Interval other)
  18. {
  19. if (begin < other.begin)
  20. {
  21. return -1;
  22. }
  23. else if (begin == other.begin)
  24. {
  25. if (end < other.end)
  26. {
  27. return -1;
  28. }
  29. else if (end == other.end)
  30. {
  31. return 0;
  32. }
  33. else
  34. {
  35. return 1;
  36. }
  37. }
  38. else
  39. {
  40. return 1;
  41. }
  42. }
  43. int Interval::Compare(Interval x, Interval y)
  44. {
  45. return x.CompareTo(y);
  46. }
  47. bool Interval::Equals(Interval other)
  48. {
  49. return CompareTo(other) == 0;
  50. }
  51. bool Interval::Equals(Interval x, Interval y)
  52. {
  53. return x.CompareTo(y) == 0;
  54. }
  55. int Interval::GetHashCode()
  56. {
  57. return _rotl(begin, 7) ^ end;
  58. }
  59. int Interval::GetHashCode(Interval item)
  60. {
  61. return item.GetHashCode();
  62. }
  63. }