ngtcp2_range.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2017 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGTCP2_RANGE_H
  26. #define NGTCP2_RANGE_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. /*
  32. * ngtcp2_range represents half-closed range [begin, end).
  33. */
  34. typedef struct ngtcp2_range {
  35. uint64_t begin;
  36. uint64_t end;
  37. } ngtcp2_range;
  38. /*
  39. * ngtcp2_range_init initializes |r| with the range [|begin|, |end|).
  40. */
  41. void ngtcp2_range_init(ngtcp2_range *r, uint64_t begin, uint64_t end);
  42. /*
  43. * ngtcp2_range_intersect returns the intersection of |a| and |b|. If
  44. * they do not overlap, it returns empty range.
  45. */
  46. ngtcp2_range ngtcp2_range_intersect(const ngtcp2_range *a,
  47. const ngtcp2_range *b);
  48. /*
  49. * ngtcp2_range_len returns the length of |r|.
  50. */
  51. uint64_t ngtcp2_range_len(const ngtcp2_range *r);
  52. /*
  53. * ngtcp2_range_eq returns nonzero if |a| equals |b|, such that
  54. * a->begin == b->begin and a->end == b->end hold.
  55. */
  56. int ngtcp2_range_eq(const ngtcp2_range *a, const ngtcp2_range *b);
  57. /*
  58. * ngtcp2_range_cut returns the left and right range after removing
  59. * |b| from |a|. This function assumes that |a| completely includes
  60. * |b|. In other words, a->begin <= b->begin and b->end <= a->end
  61. * hold.
  62. */
  63. void ngtcp2_range_cut(ngtcp2_range *left, ngtcp2_range *right,
  64. const ngtcp2_range *a, const ngtcp2_range *b);
  65. /*
  66. * ngtcp2_range_not_after returns nonzero if the right edge of |a|
  67. * does not go beyond of the right edge of |b|.
  68. */
  69. int ngtcp2_range_not_after(const ngtcp2_range *a, const ngtcp2_range *b);
  70. #endif /* !defined(NGTCP2_RANGE_H) */