diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2023-12-29 06:21:33 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2023-12-29 06:21:33 +0100 |
commit | 2d6c8fec45b23a8a28668ecf3ef281139ab778a7 (patch) | |
tree | 75d2a8538992129a83c0c2b83688289443d697e5 /source/kit/move_back.h | |
parent | 820b171245f2f14766f3accdb0246a4e2c0d596a (diff) | |
download | saw-2d6c8fec45b23a8a28668ecf3ef281139ab778a7.zip |
refactor dependencies; include dependencies source code
Diffstat (limited to 'source/kit/move_back.h')
-rw-r--r-- | source/kit/move_back.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source/kit/move_back.h b/source/kit/move_back.h new file mode 100644 index 0000000..b6eb979 --- /dev/null +++ b/source/kit/move_back.h @@ -0,0 +1,51 @@ +#ifndef KIT_MOVE_BACK_H +#define KIT_MOVE_BACK_H + +#include "types.h" + +#include <string.h> + +#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 + +#ifndef KIT_DISABLE_SHORT_NAMES +# define MOVE_BACK_INL KIT_MOVE_BACK_INL +# define MOVE_BACK KIT_MOVE_BACK +# define MOVE_BACK_REF KIT_MOVE_BACK_REF +#endif + +#endif |