From 30740ca4131d1f574718262451b4410207dc8d4e Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 14 Jul 2024 21:12:37 +0200 Subject: Reworking the build system --- kit/move_back.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 kit/move_back.h (limited to 'kit/move_back.h') diff --git a/kit/move_back.h b/kit/move_back.h new file mode 100644 index 0000000..1885f5d --- /dev/null +++ b/kit/move_back.h @@ -0,0 +1,49 @@ +#ifndef KIT_MOVE_BACK_H +#define KIT_MOVE_BACK_H + +#include "types.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define KIT_MOVE_BACK_INL(new_size, array, ...) \ + do { \ + i64 index_; \ + i64 end_ = (array).size; \ + u8 temp_[sizeof *(array).values]; \ + for (index_ = 0; index_ < end_;) { \ + if (__VA_ARGS__) { \ + end_--; \ + if (index_ != end_) { \ + memcpy(temp_, (array).values + end_, \ + sizeof *(array).values); \ + (array).values[end_] = (array).values[index_]; \ + memcpy((array).values + index_, temp_, \ + sizeof *(array).values); \ + } \ + } else \ + index_++; \ + } \ + (new_size) = end_; \ + } while (0) + +#define KIT_MOVE_BACK(new_size, array, value, cond) \ + KIT_MOVE_BACK_INL(new_size, array, \ + (cond) ((array).values[index_], (value))) + +#define KIT_MOVE_BACK_REF(new_size, array, value, cond) \ + KIT_MOVE_BACK_INL(new_size, array, \ + (cond) ((array).values + index_, (value))) + +#ifdef __cplusplus +} +#endif + +#define MOVE_BACK_INL KIT_MOVE_BACK_INL +#define MOVE_BACK KIT_MOVE_BACK +#define MOVE_BACK_REF KIT_MOVE_BACK_REF + +#endif -- cgit v1.2.3