summaryrefslogtreecommitdiff
path: root/kit/lower_bound.h
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-07-14 21:12:37 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-07-14 21:12:37 +0200
commit30740ca4131d1f574718262451b4410207dc8d4e (patch)
treefc88b16a216079397ad85b9c6b1a1c1c5712a814 /kit/lower_bound.h
parent5e3c99bb1cf1d03ea006300121265571f5008fd2 (diff)
downloadsaw-30740ca4131d1f574718262451b4410207dc8d4e.zip
Reworking the build system
Diffstat (limited to 'kit/lower_bound.h')
-rw-r--r--kit/lower_bound.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/kit/lower_bound.h b/kit/lower_bound.h
new file mode 100644
index 0000000..eb437ed
--- /dev/null
+++ b/kit/lower_bound.h
@@ -0,0 +1,42 @@
+#ifndef KIT_LOWER_BOUND_H
+#define KIT_LOWER_BOUND_H
+
+#include "types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define KIT_LOWER_BOUND_INL(return_val, size, ...) \
+ do { \
+ i64 position_ = 0; \
+ i64 count_ = (size); \
+ while (count_ > 0) { \
+ i64 delta_ = count_ / 2; \
+ i64 index_ = position_ + delta_; \
+ if (__VA_ARGS__) { \
+ position_ += delta_ + 1; \
+ count_ -= delta_ + 1; \
+ } else \
+ count_ = delta_; \
+ } \
+ (return_val) = position_; \
+ } while (0)
+
+#define KIT_LOWER_BOUND(return_val, array, value, op) \
+ KIT_LOWER_BOUND_INL(return_val, (array).size, \
+ (op) ((array).values[index_], (value)))
+
+#define KIT_LOWER_BOUND_REF(return_val, array, value, op) \
+ KIT_LOWER_BOUND_INL(return_val, (array).size, \
+ (op) ((array).values + index_, (value)))
+
+#ifdef __cplusplus
+}
+#endif
+
+#define LOWER_BOUND_INL KIT_LOWER_BOUND_INL
+#define LOWER_BOUND KIT_LOWER_BOUND
+#define LOWER_BOUND_REF KIT_LOWER_BOUND_REF
+
+#endif