==> include/mesh/range_set.h <==1/* @ajax/range-set: a set of u64 items as disjoint, non-touching half-open ranges [s, e), sorted.
2 * Inserting merges what overlaps or touches; removing splits. Lengths saturate (an endless range is
3 * ~u64::MAX items). */
4#ifndef MESH_RANGE_SET_H
5#define MESH_RANGE_SET_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10
11typedef struct {
12 uint64_t *s, *e;
13 size_t n, cap;
14} rs_set;
15
16rs_set rs_of(uint64_t s, uint64_t e);
17bool rs_is_empty(const rs_set *r);
18uint64_t rs_len(const rs_set *r); /* items, saturating */
19size_t rs_count(const rs_set *r); /* ranges */
20bool rs_first(const rs_set *r, uint64_t *x);
21bool rs_end(const rs_set *r, uint64_t *x);
22bool rs_contains(const rs_set *r, uint64_t x);
23void rs_insert(rs_set *r, uint64_t s, uint64_t e);
24void rs_add(rs_set *r, uint64_t x);
25void rs_union(rs_set *r, const rs_set *o);
26/* Removes [s, e); true if anything was in it. */
27bool rs_remove(rs_set *r, uint64_t s, uint64_t e);
28bool rs_take(rs_set *r, uint64_t x);
29void rs_subtract(rs_set *r, const rs_set *o);
30bool rs_eq(const rs_set *a, const rs_set *b);
31rs_set rs_clone(const rs_set *r);
32void rs_free(rs_set *r);
33
34#endif