fixed queue end with vector end

This commit is contained in:
Tommaso Rodolfo Masera 2019-09-01 16:07:21 +02:00
parent 8cb1bee38c
commit 5ccabd2791

View file

@ -12,7 +12,7 @@ typedef struct queue {
size_t size;
} vector_t;
inline static size_t queue_end(vector_t* self) {
inline static size_t vector_end(vector_t* self) {
return (self->start + self->size) % self->length;
}
@ -30,7 +30,7 @@ bool vector_add(vector_t* self, VECTOR_TYPE element, bool to_end) {
return false;
}
if (to_end) {
self->arr[queue_end(self)] = element;
self->arr[vector_end(self)] = element;
} else {
if (self->size == 0) {
self->arr[self->start] = element;
@ -48,7 +48,7 @@ bool vector_remove(vector_t* self, VECTOR_TYPE* destination, bool from_end) {
return false;
}
*destination = self->arr[!from_end ? queue_end(self) : self->start];
*destination = self->arr[!from_end ? vector_end(self) : self->start];
if (from_end) {
self->start = (self->start + 1) % self->length;
}