aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKirill Primak <vyivel@eclair.cafe>2022-08-19 21:20:43 +0300
committerSimon Zeni <simon@bl4ckb0ne.ca>2022-08-29 13:48:42 +0000
commit7333a4602a333c8710ada6f8a16435745aa4a557 (patch)
tree32655243a2122118263ca6b8c26442ce679e08bf /include
parent20c208d46a140e148da29730a3adbfa9b88de467 (diff)
util/set: overhaul
Diffstat (limited to 'include')
-rw-r--r--include/util/set.h26
1 files changed, 15 insertions, 11 deletions
diff --git a/include/util/set.h b/include/util/set.h
index 41099621..d6330108 100644
--- a/include/util/set.h
+++ b/include/util/set.h
@@ -2,24 +2,28 @@
#define UTIL_SET_H
#include <stdint.h>
-#include <stdlib.h>
#include <stdbool.h>
-
-size_t push_zeroes_to_end(uint32_t arr[], size_t n);
+#include <sys/types.h>
/**
- * Add `target` to `values` if it doesn't exist
- * "set"s should only be modified with set_* functions
- * Values MUST be greater than 0
+ * Add target to values.
+ *
+ * Target is added to the end of the set.
+ *
+ * Returns the index of target, or -1 if the set is full or target already
+ * exists.
*/
-bool set_add(uint32_t values[], size_t *len, size_t cap, uint32_t target);
+ssize_t set_add(uint32_t values[], size_t *len, size_t cap, uint32_t target);
/**
- * Remove `target` from `values` if it exists
- * "set"s should only be modified with set_* functions
- * Values MUST be greater than 0
+ * Remove target from values.
+ *
+ * When target is removed, the last element of the set is moved to where
+ * target was.
+ *
+ * Returns the previous index of target, or -1 if target wasn't in values.
*/
-bool set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target);
+ssize_t set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target);
#endif