summaryrefslogtreecommitdiffstats
path: root/src/vector.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-04-25 00:13:44 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-04-25 00:13:44 +0200
commit53b74ddf2cfe0f654724c3a1aca16e7fb6044ae5 (patch)
treebf2f43cae23337426321f515cbce54a933cedf46 /src/vector.h
parent4ea57586f53dad8e567d2072c5567b92e8902d8c (diff)
downloadfastd-53b74ddf2cfe0f654724c3a1aca16e7fb6044ae5.tar
fastd-53b74ddf2cfe0f654724c3a1aca16e7fb6044ae5.zip
vector: add VECTOR_BSEARCH macro and use where appropriate
Diffstat (limited to 'src/vector.h')
-rw-r--r--src/vector.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/vector.h b/src/vector.h
index 701b64e..0396c01 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -81,3 +81,10 @@ void _fastd_vector_delete(fastd_vector_desc_t *desc, void **data, size_t pos, si
__typeof__(v) *_v = &(v); \
_fastd_vector_delete(&_v->desc, (void**)&_v->data, (pos), sizeof(*_v->data)); \
})
+
+#define VECTOR_BSEARCH(key, v, cmp) ({ \
+ __typeof__(v) *_v = &(v); \
+ const __typeof__(*_v->data) *_key = (key); \
+ int (*_cmp)(__typeof__(_key), __typeof__(_key)) = (cmp); \
+ (__typeof__(_v->data))bsearch(_key, _v->data, _v->desc.length, sizeof(*_v->data), (int (*)(const void *, const void *))_cmp); \
+ })