blob: 1366d04f8fc1dd6fa8baae68610dc424dd906b45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "util/set.h"
ssize_t set_add(uint32_t values[], size_t *len, size_t cap, uint32_t target) {
for (uint32_t i = 0; i < *len; ++i) {
if (values[i] == target) {
return i;
}
}
if (*len == cap) {
return -1;
}
values[*len] = target;
return (*len)++;
}
ssize_t set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target) {
for (uint32_t i = 0; i < *len; ++i) {
if (values[i] == target) {
--(*len);
values[i] = values[*len];
return i;
}
}
return -1;
}
|