diff --git a/lab01/zad1/include/queue.h b/lab01/zad1/include/queue.h index 29d233c..cabb895 100644 --- a/lab01/zad1/include/queue.h +++ b/lab01/zad1/include/queue.h @@ -6,7 +6,7 @@ typedef struct Queue Queue; -Queue *queue_new(size_t size, size_t element_size); +Queue *queue_new(size_t length, size_t element_size); void queue_free(Queue *queue); diff --git a/lab01/zad1/src/queue.c b/lab01/zad1/src/queue.c index d0b7579..455441a 100644 --- a/lab01/zad1/src/queue.c +++ b/lab01/zad1/src/queue.c @@ -6,18 +6,18 @@ struct Queue { size_t back; size_t front; - size_t size; + size_t length; size_t element_size; void **data; }; -Queue *queue_new(size_t size, size_t element_size) { +Queue *queue_new(size_t length, size_t element_size) { Queue *ret = malloc(sizeof(Queue)); ret->back = 0; ret->front = 0; - ret->size = size; + ret->length = length; ret->element_size = element_size; - ret->data = malloc(size * sizeof(void*)); + ret->data = malloc(length * sizeof(void*)); return ret; } @@ -38,18 +38,18 @@ void *queue_read(Queue *q) { void* ret = memcpy(malloc(q->element_size), q->data[q->front], q->element_size); q->data[q->front] = NULL; - q->front = (q->front + 1) % q->size; + q->front = (q->front + 1) % q->length; return ret; } bool queue_write(Queue *q, void *value) { - if (((q->back + 1) % q->size) == q->front) { + if (((q->back + 1) % q->length) == q->front) { return false; } void *local_value = memcpy(malloc(q->element_size), value, q->element_size); q->data[q->back] = local_value; - q->back = (q->back + 1) % q->size; + q->back = (q->back + 1) % q->length; return true; }