fixed queue end with vector end
This commit is contained in:
parent
8cb1bee38c
commit
5ccabd2791
1 changed files with 3 additions and 3 deletions
|
@ -12,7 +12,7 @@ typedef struct queue {
|
||||||
size_t size;
|
size_t size;
|
||||||
} vector_t;
|
} 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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (to_end) {
|
if (to_end) {
|
||||||
self->arr[queue_end(self)] = element;
|
self->arr[vector_end(self)] = element;
|
||||||
} else {
|
} else {
|
||||||
if (self->size == 0) {
|
if (self->size == 0) {
|
||||||
self->arr[self->start] = element;
|
self->arr[self->start] = element;
|
||||||
|
@ -48,7 +48,7 @@ bool vector_remove(vector_t* self, VECTOR_TYPE* destination, bool from_end) {
|
||||||
return false;
|
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) {
|
if (from_end) {
|
||||||
self->start = (self->start + 1) % self->length;
|
self->start = (self->start + 1) % self->length;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue