1 // SPDX-License-Identifier: MIT
7 * sset.h - an all O(1) implementation of sparse sets as presented in:
8 * "An Efficient Representation for Sparse Sets"
9 * by Preston Briggs and Linda Torczon
11 * Copyright (C) 2017 - Luc Van Oostenryck
23 extern struct sset
*sset_init(unsigned int size
, unsigned int off
);
24 extern void sset_free(struct sset
*s
);
27 static inline void sset_reset(struct sset
*s
)
32 static inline void sset_add(struct sset
*s
, unsigned int idx
)
34 unsigned int __idx
= idx
- s
->off
;
35 unsigned int n
= s
->nbr
++;
37 s
->sets
[s
->size
+ n
] = __idx
;
40 static inline bool sset_test(struct sset
*s
, unsigned int idx
)
42 unsigned int __idx
= idx
- s
->off
;
43 unsigned int n
= s
->sets
[__idx
];
45 return (n
< s
->nbr
) && (s
->sets
[s
->size
+ n
] == __idx
);
48 static inline bool sset_testset(struct sset
*s
, unsigned int idx
)
50 if (sset_test(s
, idx
))