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 28 #ifdef HAVE_CONFIG_H 29 # include <config.h> 30 #endif /* HAVE_CONFIG_H */ 31 32 #include <ngtcp2/ngtcp2.h> 33 34 /* 35 * ngtcp2_range represents half-closed range [begin, end). 36 */ 37 typedef struct ngtcp2_range { 38 uint64_t begin; 39 uint64_t end; 40 } ngtcp2_range; 41 42 /* 43 * ngtcp2_range_init initializes |r| with the range [|begin|, |end|). 44 */ 45 void ngtcp2_range_init(ngtcp2_range *r, uint64_t begin, uint64_t end); 46 47 /* 48 * ngtcp2_range_intersect returns the intersection of |a| and |b|. If 49 * they do not overlap, it returns empty range. 50 */ 51 ngtcp2_range ngtcp2_range_intersect(const ngtcp2_range *a, 52 const ngtcp2_range *b); 53 54 /* 55 * ngtcp2_range_len returns the length of |r|. 56 */ 57 uint64_t ngtcp2_range_len(const ngtcp2_range *r); 58 59 /* 60 * ngtcp2_range_eq returns nonzero if |a| equals |b|, such that 61 * a->begin == b->begin, and a->end == b->end hold. 62 */ 63 int ngtcp2_range_eq(const ngtcp2_range *a, const ngtcp2_range *b); 64 65 /* 66 * ngtcp2_range_cut returns the left and right range after removing 67 * |b| from |a|. This function assumes that |a| completely includes 68 * |b|. In other words, a->begin <= b->begin and b->end <= a->end 69 * hold. 70 */ 71 void ngtcp2_range_cut(ngtcp2_range *left, ngtcp2_range *right, 72 const ngtcp2_range *a, const ngtcp2_range *b); 73 74 /* 75 * ngtcp2_range_not_after returns nonzero if the right edge of |a| 76 * does not go beyond of the right edge of |b|. 77 */ 78 int ngtcp2_range_not_after(const ngtcp2_range *a, const ngtcp2_range *b); 79 80 #endif /* NGTCP2_RANGE_H */ 81