From 07bb3643447806fed65329ca4a0da0460bf7e7b9 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 10 Sep 2020 10:05:27 +0200 Subject: Reformatting only. --- stc/cpqueue.h | 155 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 78 insertions(+), 77 deletions(-) (limited to 'stc/cpqueue.h') diff --git a/stc/cpqueue.h b/stc/cpqueue.h index ea8bd0ed..47612e2c 100644 --- a/stc/cpqueue.h +++ b/stc/cpqueue.h @@ -51,88 +51,89 @@ #include "cvec.h" #define declare_cpqueue(X, ctype, cmpOpr) /* cmpOpr: < or > */ \ - \ -typedef struct ctype cpqueue_##X; \ -typedef ctype##_value_t cpqueue_##X##_value_t; \ -typedef ctype##_rawvalue_t cpqueue_##X##_rawvalue_t; \ -typedef ctype##_input_t cpqueue_##X##_input_t; \ -STC_INLINE cpqueue_##X \ -cpqueue_##X##_init() {return ctype##_init();} \ -STC_INLINE size_t \ -cpqueue_##X##_size(cpqueue_##X pq) {return ctype##_size(pq);} \ -STC_INLINE bool \ -cpqueue_##X##_empty(cpqueue_##X pq) {return ctype##_empty(pq);} \ -STC_INLINE void \ -cpqueue_##X##_destroy(cpqueue_##X* self) {ctype##_destroy(self);} \ -STC_API void \ -cpqueue_##X##_build(cpqueue_##X* self); \ -STC_API void \ -cpqueue_##X##_erase(cpqueue_##X* self, size_t i); \ -STC_INLINE const cpqueue_##X##_value_t* \ -cpqueue_##X##_top(const cpqueue_##X* self) {return &self->data[0];} \ -STC_INLINE void \ -cpqueue_##X##_pop(cpqueue_##X* self) {cpqueue_##X##_erase(self, 0);} \ -STC_API void \ -cpqueue_##X##_push(cpqueue_##X* self, cpqueue_##X##_value_t value); \ -STC_INLINE void \ -cpqueue_##X##_emplace(cpqueue_##X* self, cpqueue_##X##_rawvalue_t rawValue) { \ - cpqueue_##X##_push(self, ctype##_value_from_raw(rawValue)); \ -} \ -STC_API void \ -cpqueue_##X##_push_n(cpqueue_##X *self, const cpqueue_##X##_input_t in[], size_t size); \ - \ -implement_cpqueue(X, ctype, cmpOpr) - +\ + typedef struct ctype cpqueue_##X; \ + typedef ctype##_value_t cpqueue_##X##_value_t; \ + typedef ctype##_rawvalue_t cpqueue_##X##_rawvalue_t; \ + typedef ctype##_input_t cpqueue_##X##_input_t; \ + STC_INLINE cpqueue_##X \ + cpqueue_##X##_init() {return ctype##_init();} \ + STC_INLINE size_t \ + cpqueue_##X##_size(cpqueue_##X pq) {return ctype##_size(pq);} \ + STC_INLINE bool \ + cpqueue_##X##_empty(cpqueue_##X pq) {return ctype##_empty(pq);} \ + STC_INLINE void \ + cpqueue_##X##_destroy(cpqueue_##X* self) {ctype##_destroy(self);} \ + STC_API void \ + cpqueue_##X##_build(cpqueue_##X* self); \ + STC_API void \ + cpqueue_##X##_erase(cpqueue_##X* self, size_t i); \ + STC_INLINE const cpqueue_##X##_value_t* \ + cpqueue_##X##_top(const cpqueue_##X* self) {return &self->data[0];} \ + STC_INLINE void \ + cpqueue_##X##_pop(cpqueue_##X* self) {cpqueue_##X##_erase(self, 0);} \ + STC_API void \ + cpqueue_##X##_push(cpqueue_##X* self, cpqueue_##X##_value_t value); \ + STC_INLINE void \ + cpqueue_##X##_emplace(cpqueue_##X* self, cpqueue_##X##_rawvalue_t rawValue) { \ + cpqueue_##X##_push(self, ctype##_value_from_raw(rawValue)); \ + } \ + STC_API void \ + cpqueue_##X##_push_n(cpqueue_##X *self, const cpqueue_##X##_input_t in[], size_t size); \ +\ + implement_cpqueue(X, ctype, cmpOpr) + /* -------------------------- IMPLEMENTATION ------------------------- */ #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION) #define implement_cpqueue(X, ctype, cmpOpr) \ - \ -STC_INLINE void \ -_cpqueue_##X##_sift_down(cpqueue_##X##_value_t* arr, size_t i, size_t n) { \ - size_t r = i, c = i << 1; \ - while (c <= n) { \ - if (c < n && ctype##_value_compare(&arr[c], &arr[c + 1]) cmpOpr 0) \ - ++c; \ - if (ctype##_value_compare(&arr[r], &arr[c]) cmpOpr 0) { \ - cpqueue_##X##_value_t tmp = arr[r]; arr[r] = arr[c]; arr[r = c] = tmp; \ - } else \ - return; \ - c <<= 1; \ +\ + STC_INLINE void \ + _cpqueue_##X##_sift_down(cpqueue_##X##_value_t* arr, size_t i, size_t n) { \ + size_t r = i, c = i << 1; \ + while (c <= n) { \ + if (c < n && ctype##_value_compare(&arr[c], &arr[c + 1]) cmpOpr 0) \ + ++c; \ + if (ctype##_value_compare(&arr[r], &arr[c]) cmpOpr 0) { \ + cpqueue_##X##_value_t tmp = arr[r]; arr[r] = arr[c]; arr[r = c] = tmp; \ + } else \ + return; \ + c <<= 1; \ + } \ + } \ +\ + STC_API void \ + cpqueue_##X##_build(cpqueue_##X* self) { \ + size_t n = cpqueue_##X##_size(*self); \ + cpqueue_##X##_value_t *arr = self->data - 1; \ + for (size_t k = n >> 1; k != 0; --k) \ + _cpqueue_##X##_sift_down(arr, k, n); \ + } \ +\ + STC_API void \ + cpqueue_##X##_erase(cpqueue_##X* self, size_t i) { \ + size_t n = cpqueue_##X##_size(*self) - 1; \ + self->data[i] = self->data[n]; \ + ctype##_pop_back(self); \ + _cpqueue_##X##_sift_down(self->data - 1, i + 1, n); \ + } \ +\ + STC_API void \ + cpqueue_##X##_push(cpqueue_##X* self, cpqueue_##X##_value_t value) { \ + ctype##_push_back(self, value); /* sift-up the value */ \ + size_t n = cpqueue_##X##_size(*self), c = n; \ + cpqueue_##X##_value_t *arr = self->data - 1; \ + for (; c > 1 && ctype##_value_compare(&arr[c >> 1], &value) cmpOpr 0; c >>= 1) \ + arr[c] = arr[c >> 1]; \ + if (c != n) arr[c] = value; \ + } \ + STC_API void \ + cpqueue_##X##_push_n(cpqueue_##X *self, const cpqueue_##X##_input_t in[], size_t size) { \ + ctype##_reserve(self, cpqueue_##X##_size(*self) + size); \ + for (size_t i=0; idata - 1; \ - for (size_t k = n >> 1; k != 0; --k) \ - _cpqueue_##X##_sift_down(arr, k, n); \ -} \ - \ -STC_API void \ -cpqueue_##X##_erase(cpqueue_##X* self, size_t i) { \ - size_t n = cpqueue_##X##_size(*self) - 1; \ - self->data[i] = self->data[n]; \ - ctype##_pop_back(self); \ - _cpqueue_##X##_sift_down(self->data - 1, i + 1, n); \ -} \ - \ -STC_API void \ -cpqueue_##X##_push(cpqueue_##X* self, cpqueue_##X##_value_t value) { \ - ctype##_push_back(self, value); /* sift-up the value */ \ - size_t n = cpqueue_##X##_size(*self), c = n; \ - cpqueue_##X##_value_t *arr = self->data - 1; \ - for (; c > 1 && ctype##_value_compare(&arr[c >> 1], &value) cmpOpr 0; c >>= 1) \ - arr[c] = arr[c >> 1]; \ - if (c != n) arr[c] = value; \ -} \ -STC_API void \ -cpqueue_##X##_push_n(cpqueue_##X *self, const cpqueue_##X##_input_t in[], size_t size) { \ - ctype##_reserve(self, cpqueue_##X##_size(*self) + size); \ - for (size_t i=0; i