You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
497 B
26 lines
497 B
#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;
|
|
}
|