summaryrefslogtreecommitdiffstats
path: root/lib/libdvec/include/dvec.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libdvec/include/dvec.h')
-rw-r--r--lib/libdvec/include/dvec.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/libdvec/include/dvec.h b/lib/libdvec/include/dvec.h
index 3dfed36..45888a6 100644
--- a/lib/libdvec/include/dvec.h
+++ b/lib/libdvec/include/dvec.h
@@ -3,16 +3,23 @@
#include "allocator.h"
#include <sys/types.h>
+#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
+#define DVEC_ERRNO(rc) ((rc) > 0 && (rc) & (1 << 30) ? (rc) & ~(1 << 30) : 0)
+#define DVEC_ERR(lut, rc) errx(1, "libdvec: %s", \
+ (rc) == DVEC_BAD ? lut[0] : (DVEC_ERRNO(rc) ? strerror(DVEC_ERRNO(rc)) : lut[rc+1]))
+
#define DVEC_ITER(dvec, p) (p) = NULL; ((p) = dvec_iter_fwd((dvec), (p)));
#define DVEC_ITER_BWD(dvec, p) (p) = NULL; ((p) = dvec_iter_bwd((dvec), (p)));
#define DVEC_STRERR_INIT \
- [DVEC_OK] = "Success", \
- [DVEC_LOCKED] = "Data vector locked"
+ [0] = "Failure", \
+ [1+DVEC_OK] = "Success", \
+ [1+DVEC_LOCKED] = "Locked", \
+ [1+DVEC_MODIFIED] = "Modified"
#ifdef LIBDVEC_ASSERT_ARGS
#include "stdlib.h"
@@ -29,8 +36,10 @@
#endif
enum {
+ DVEC_BAD = -1 & INT_MAX,
DVEC_OK = 0,
- DVEC_LOCKED = 1,
+ DVEC_LOCKED = 1 << 0,
+ DVEC_MODIFIED = 1 << 1
};
struct dvec {
@@ -42,8 +51,8 @@ struct dvec {
const struct allocator *allocator;
};
-typedef bool (*dvec_sort_order_fn)(const void *p1, const void *p2, void *u);
-typedef int (*dvec_search_cmp_fn)(const void *cur, void *user);
+typedef bool (*dvec_sort_order_fn)(const void *left, const void *right, const void *user);
+typedef int (*dvec_search_cmp_fn)(const void *other, const void *user);
int dvec_init(struct dvec *dvec, size_t dsize, size_t cap,
const struct allocator *allocator);
@@ -72,9 +81,9 @@ void *dvec_iter_fwd(const struct dvec *dvec, const void *p);
void *dvec_iter_bwd(const struct dvec *dvec, const void *p);
int dvec_quick_sort(struct dvec *dvec, const struct allocator *allocator,
- void *tmp, bool reverse, dvec_sort_order_fn in_order, void *user);
+ void *tmp, bool reverse, dvec_sort_order_fn in_order, const void *user);
int dvec_quick_sort_ex(struct dvec *dvec, const struct allocator *allocator,
- void *tmp, bool reverse, dvec_sort_order_fn in_order, void *user);
+ void *tmp, bool reverse, dvec_sort_order_fn in_order, const void *user);
ssize_t dvec_binary_search(struct dvec *dvec, dvec_search_cmp_fn search_cmp,
void *user, ssize_t *lower, ssize_t *higher);