This commit is contained in:
2026-08-31 22:49:42 +08:00
parent 109e8af3d5
commit 4e5ae52e54
35 changed files with 3606 additions and 22 deletions
+9 -9
View File
@@ -1,6 +1,6 @@
#include <c_StringList.h>
c_err_t c_StringList_Init(c_StringList* self, c_size_t capacity, c_Allocator_t* allocator) {
c_err_t c_StringList_Init(c_StringList_t* self, c_size_t capacity, c_Allocator_t* allocator) {
if (!self) return C_ERR_PARAM;
self->allocator = (allocator != NULL) ? *allocator : c_DefaultAllocator;
@@ -19,7 +19,7 @@ c_err_t c_StringList_Init(c_StringList* self, c_size_t capacity, c_Allocator_t*
return C_ERR_OK;
}
void c_StringList_Clear(c_StringList* self) {
void c_StringList_Clear(c_StringList_t* self) {
if (!self || !self->strings) return;
// 【核心深清算】:必须先顺着槽位将当前持有的每一个独占字符串物理火化,退还给内置分配器
@@ -32,7 +32,7 @@ void c_StringList_Clear(c_StringList* self) {
self->size = 0;
}
void c_StringList_Destroy(c_StringList* self) {
void c_StringList_Destroy(c_StringList_t* self) {
if (!self) return;
if (self->strings) {
@@ -48,7 +48,7 @@ void c_StringList_Destroy(c_StringList* self) {
* @note 强异常安全性:若分配器因碎片满或爆仓返回 NULL,原有数据指针及老矩阵原样完整留存,绝不发生物理跑飞
*/
C_STATIC_FORCE_INLINE
bool c_StringList_EnsureCapacity(c_StringList* self) {
bool c_StringList_EnsureCapacity(c_StringList_t* self) {
if (self->size < self->capacity) return true;
c_size_t old_bytes = self->capacity * sizeof(char*);
@@ -73,7 +73,7 @@ bool c_StringList_EnsureCapacity(c_StringList* self) {
// 2. 核心深度值复制增删控制操作 API
// ==================================================================================================================
c_err_t c_StringList_InsertAt(c_StringList* self, c_size_t index, const char* str) {
c_err_t c_StringList_InsertAt(c_StringList_t* self, c_size_t index, const char* str) {
if (!self || !str || index > self->size) return C_ERR_PARAM;
if (!c_StringList_EnsureCapacity(self)) return C_ERR_NOMEM;
@@ -93,11 +93,11 @@ c_err_t c_StringList_InsertAt(c_StringList* self, c_size_t index, const char* st
return C_ERR_OK;
}
c_err_t c_StringList_Add(c_StringList* self, const char* str) {
c_err_t c_StringList_Add(c_StringList_t* self, const char* str) {
return c_StringList_InsertAt(self, self->size, str); // 末尾追加
}
c_err_t c_StringList_RemoveAt(c_StringList* self, c_size_t index) {
c_err_t c_StringList_RemoveAt(c_StringList_t* self, c_size_t index) {
if (!self || index >= self->size || !self->strings) return C_ERR_PARAM;
// ① 定点火化销毁当前槽位持有的独占堆字符串,归还空间
@@ -118,7 +118,7 @@ c_err_t c_StringList_RemoveAt(c_StringList* self, c_size_t index) {
// 3. 高级功能:链表深克隆与高速去重
// ==================================================================================================================
c_err_t c_StringList_Clone(c_StringList* dest, const c_StringList* src) {
c_err_t c_StringList_Clone(c_StringList_t* dest, const c_StringList_t* src) {
if (!dest || !src || dest == src || !src->strings) return C_ERR_PARAM;
// 清算 dest 先前绑定的生命线
@@ -139,7 +139,7 @@ c_err_t c_StringList_Clone(c_StringList* dest, const c_StringList* src) {
return C_ERR_OK;
}
c_err_t c_StringList_Deduplicate(c_StringList* self) {
c_err_t c_StringList_Deduplicate(c_StringList_t* self) {
if (!self || self->size <= 1 || !self->strings) return C_ERR_OK;
// O(N^2) 经典原位原地重排去重流