File Coverage

ds_iset.h
Criterion Covered Total %
statement 5 5 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 5 5 100.0


line stmt bran cond sub pod time code
1             #ifndef MPU_DS_ISET_H
2             #define MPU_DS_ISET_H
3              
4             #include "ptypes.h"
5              
6             /******************************************************************************/
7             /* INTEGER SET DATA STRUCTURE */
8             /******************************************************************************/
9              
10             #define ISET_TYPE_ANY 0
11             #define ISET_TYPE_UV 1
12             #define ISET_TYPE_IV 2
13             #define ISET_TYPE_INVALID 3
14              
15             typedef struct {
16             UV *arr;
17             size_t mask;
18             size_t maxsize;
19             size_t size;
20             bool contains_zero;
21             unsigned char type;
22             } iset_t;
23              
24             iset_t iset_create(size_t init_size);
25             void iset_destroy(iset_t *set);
26              
27             iset_t iset_create_from_array(UV* d, size_t dlen, int dsign);
28              
29             /* Returns 1 if unsigned, -1 if signed, 0 if messed up. */
30 76           static int iset_sign(const iset_t set) {
31             static const signed char _iset_typeret[4] = {1,1,-1,0};
32 76           return _iset_typeret[set.type];
33             }
34 259           static int iset_is_invalid(const iset_t set)
35 259           { return set.type == ISET_TYPE_INVALID; }
36              
37 45           static size_t iset_size(const iset_t set) { return set.size; }
38              
39             bool iset_contains(const iset_t set, UV val); /* returns 0 or 1 */
40              
41             /* void iset_minmax(const iset_t set, UV *min, UV *max); */
42              
43             /* sign indicates: val is a UV (1) or IV (-1) */
44             bool iset_add(iset_t *set, UV val, int sign); /* Returns 1 if added, 0 if not */
45              
46             /* This would require non-trivial changes to handle chains */
47             /* void iset_remove(iset_t *set, UV val); */
48              
49             /* We could make an iterator */
50              
51             /* caller supplied array must have room */
52             void iset_allvals(const iset_t set, UV* array);
53              
54             void iset_union_with(iset_t *set, const iset_t L);
55             void iset_intersect_with(iset_t *set, const iset_t L);
56             void iset_difference_with(iset_t *set, const iset_t L);
57             void iset_symdiff_with(iset_t *set, const iset_t L);
58              
59             iset_t iset_union_of(const iset_t A, const iset_t B);
60             iset_t iset_intersection_of(const iset_t A, const iset_t B);
61             iset_t iset_difference_of(const iset_t A, const iset_t B);
62             iset_t iset_symdiff_of(const iset_t A, const iset_t B);
63             bool iset_is_subset_of(const iset_t A, const iset_t B); /* A subset of B? */
64              
65             void iset_test(void);
66              
67             #endif