mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 23:56:54 +08:00
头索引或者入队还存在问题,稍后回来继续解决。
This commit is contained in:
parent
b2c20b9dca
commit
0ee0eb90b0
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -5,6 +5,7 @@
|
||||
"common.h": "c",
|
||||
"unicstl.h": "c",
|
||||
"test.h": "c",
|
||||
"queue.h": "c"
|
||||
"queue.h": "c",
|
||||
"stdbool.h": "c"
|
||||
}
|
||||
}
|
18
src/queue.c
18
src/queue.c
@ -301,11 +301,14 @@ bool queue2_push(struct _queue* self, void* obj)
|
||||
}
|
||||
void * obj_array = self->_front->obj;
|
||||
uint32_t index = self->_index_back;
|
||||
index++;
|
||||
if(index >= self->capacity(self))
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
index++;
|
||||
}
|
||||
memmove((char*)obj_array + index * self->_obj_size, obj, self->_obj_size);
|
||||
self->_index_back = index;
|
||||
self->_size++;
|
||||
@ -322,13 +325,13 @@ bool queue2_pop(struct _queue* self, void* obj)
|
||||
void * obj_array = self->_front->obj;
|
||||
uint32_t index = self->_index_front;
|
||||
|
||||
if(index == 0)
|
||||
if(index >= self->capacity(self))
|
||||
{
|
||||
index = self->capacity(self) - 1;
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
index--;
|
||||
index++;
|
||||
}
|
||||
if(obj != NULL)
|
||||
{
|
||||
@ -348,7 +351,7 @@ bool queue2_back(struct _queue* self, void* obj)
|
||||
}
|
||||
void * obj_array = self->_front->obj;
|
||||
uint32_t index = self->_index_back;
|
||||
memmove(obj, obj_array + self->_obj_size, self->_obj_size);
|
||||
memmove(obj, (char *)obj_array + self->_obj_size, self->_obj_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -361,7 +364,7 @@ bool queue2_front(struct _queue* self, void* obj)
|
||||
}
|
||||
void * obj_array = self->_front->obj;
|
||||
uint32_t index = self->_index_front;
|
||||
memmove(obj, obj_array + index * self->_obj_size, self->_obj_size);
|
||||
memmove(obj, (char *)obj_array + index * self->_obj_size, self->_obj_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -428,6 +431,7 @@ bool queue2_init(struct _queue * queue, uint32_t obj_size, uint32_t capacity)
|
||||
queue->front = queue2_front;
|
||||
queue->clear = queue2_clear;
|
||||
queue->empty = queue_empty;
|
||||
queue->full = queue2_full;
|
||||
queue->size = queue_size;
|
||||
queue->capacity = queue2_capacity;
|
||||
queue->destory = queue2_destory;
|
||||
@ -439,7 +443,7 @@ bool queue2_init(struct _queue * queue, uint32_t obj_size, uint32_t capacity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
queue->_back = queue->_back;
|
||||
queue->_back = queue->_front;
|
||||
|
||||
queue->_front->obj = calloc(queue->_capacity + 1, queue->_obj_size);
|
||||
if(queue->_front->obj == NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user