summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-05-26 04:02:39 +0200
committerLouis Burda <quent.burda@gmail.com>2023-05-26 04:02:39 +0200
commit046c59cd98066bc1fe9e48a27e048213ea80dede (patch)
treef149ad43acad9862fc83993ae80d3d0520d8b920 /include
parentf2542dd0d235474b6df46dcb7f5b4eafbccfde48 (diff)
downloadlibdvec-c-046c59cd98066bc1fe9e48a27e048213ea80dede.tar.gz
libdvec-c-046c59cd98066bc1fe9e48a27e048213ea80dede.zip
Add bubble sort and binary search
Diffstat (limited to 'include')
-rw-r--r--include/dvec.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/dvec.h b/include/dvec.h
index 31be5a6..9ce2c08 100644
--- a/include/dvec.h
+++ b/include/dvec.h
@@ -2,6 +2,7 @@
#include "allocator.h"
+#include <sys/types.h>
#include <stdbool.h>
#include <stddef.h>
@@ -38,6 +39,9 @@ struct dvec {
const struct allocator *allocator;
};
+typedef bool (*dvec_sort_order_fn)(const void *p1, const void *p2);
+typedef int (*dvec_search_cmp_fn)(const void *cur, void *user);
+
int dvec_init(struct dvec *dvec, size_t dsize, size_t cap,
const struct allocator *allocator);
int dvec_deinit(struct dvec *dvec);
@@ -62,6 +66,12 @@ void dvec_replace(struct dvec *dvec, size_t index,
void *dvec_iter_fwd(const struct dvec *dvec, const void *p);
void *dvec_iter_bwd(const struct dvec *dvec, const void *p);
+int dvec_bubble_sort(struct dvec *dvec,
+ bool reverse, dvec_sort_order_fn in_order);
+
+ssize_t dvec_binary_search(struct dvec *dvec, dvec_search_cmp_fn search_cmp,
+ void *user, ssize_t *lower, ssize_t *higher);
+
static inline void *
dvec_at(const struct dvec *dvec, size_t index)
{