11#ifndef UTILS_GP_CIRCULAR_BUFFER_H
12#define UTILS_GP_CIRCULAR_BUFFER_H
52 size_t old_last = self->
last;
71 return (idx+1) % self->
size;
151#define GP_CBUFFER_FOREACH(self, iter) \
152 for ((iter)->idx = gp_cbuffer_first(self), (iter)->cnt = 0; \
153 (iter)->cnt < (self)->used; \
154 (iter)->idx = gp_cbuffer_next(self, (iter)->idx), (iter)->cnt++)
164#define GP_CBUFFER_FORRANGE(self, iter, skip, count) \
165 if ((self)->used > skip) \
166 for ((iter)->idx = (gp_cbuffer_first(self) + skip) % (self)->size, (iter)->cnt = 0; \
167 (iter)->cnt < GP_MIN((self)->used - skip, count); \
168 (iter)->idx = gp_cbuffer_next(self, (iter)->idx), (iter)->cnt++)
176#define GP_CBUFFER_FOREACH_REV(self, iter) \
177 for ((iter)->idx = gp_cbuffer_last(self), (iter)->cnt = 0; \
178 (iter)->cnt < (self)->used; \
179 (iter)->idx = gp_cbuffer_prev(self, (iter)->idx), (iter)->cnt++)
static size_t gp_cbuffer_next(gp_cbuffer *self, size_t idx)
Returns next position in the circular buffer.
static size_t gp_cbuffer_append(gp_cbuffer *self)
Appends into circular buffer.
static size_t gp_cbuffer_used(gp_cbuffer *self)
Returns number of used positions in the circular buffer.
static size_t gp_cbuffer_first(gp_cbuffer *self)
Returns index to the first element in buffer.
static size_t gp_cbuffer_prev(gp_cbuffer *self, size_t idx)
Returns previous position in the circular buffer.
static void gp_cbuffer_init(gp_cbuffer *self, size_t size)
Initializes circular buffer.
static size_t gp_cbuffer_last(gp_cbuffer *self)
Returns index to the last element in buffer.
An interator for loops over the circular buffer.
A circular buffer indexes.