测试用例
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include <c_ArrayQueue.h>
|
||||
#include <c_Memory.h>
|
||||
|
||||
#define DEFAULT_INITIAL_CAPACITY 4
|
||||
#define DEFAULT_INITIAL_CAPACITY 4
|
||||
#define MIN_SHRINK_CAPACITY 4
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
@@ -72,6 +73,18 @@ c_err_t c_ArrayQueue_Pop(c_ArrayQueue_t* self, void* obj) {
|
||||
}
|
||||
|
||||
self->size--;
|
||||
|
||||
if (self->size > 0 && self->size <= (self->capacity >> 2)) {
|
||||
c_size_t new_capacity = self->capacity >> 1; // 容量减半
|
||||
|
||||
void* new_array = C_REALLOC(self->array, new_capacity * self->obj_size);
|
||||
if (new_array) { // 如果 realloc 失败不影响原有数据安全,这里采用安全赋值
|
||||
self->array = new_array;
|
||||
self->capacity = new_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return C_ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user