54 lines
1.8 KiB
C
54 lines
1.8 KiB
C
#ifndef INCLUDED_C_STRINGLIST_H
|
|
#define INCLUDED_C_STRINGLIST_H
|
|
|
|
#ifndef INCLUDED_C_TYPES_H
|
|
#include <c_Types.h>
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
|
|
|
#ifndef INCLUDED_C_ALLOCATOR_H
|
|
#include <c_Allocator.h>
|
|
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
typedef struct {
|
|
char** strings; // Dynamic array of self-owned null-terminated strings
|
|
c_size_t size; // Current active string rows stored
|
|
c_size_t capacity; // Max allocated capacity bounds of the internal pointer matrix
|
|
c_Allocator_t allocator;
|
|
} c_StringList;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
c_err_t c_StringList_Init(c_StringList* self, c_size_t capacity, c_Allocator_t* allocator);
|
|
void c_StringList_Destroy(c_StringList* self);
|
|
|
|
// 核心操作 API (安全深拷贝值复制模式)
|
|
c_err_t c_StringList_Add(c_StringList* self, const char* str);
|
|
c_err_t c_StringList_InsertAt(c_StringList* self, c_size_t index, const char* str);
|
|
c_err_t c_StringList_RemoveAt(c_StringList* self, c_size_t index);
|
|
void c_StringList_Clear(c_StringList* self);
|
|
|
|
// 高级功能接口
|
|
c_err_t c_StringList_Clone(c_StringList* dest, const c_StringList* src);
|
|
c_err_t c_StringList_Deduplicate(c_StringList* self);
|
|
|
|
// 极致高频内联只读窥探接口
|
|
C_STATIC_FORCE_INLINE
|
|
c_size_t c_StringList_Size(const c_StringList* self) {
|
|
return self ? self->size : 0; // O(1) 实时读取
|
|
}
|
|
|
|
C_STATIC_FORCE_INLINE
|
|
const char* c_StringList_Get(const c_StringList* self, c_size_t index) {
|
|
if (!self || index >= self->size || !self->strings) return NULL;
|
|
return self->strings[index]; // 零拷贝原位返回
|
|
}
|
|
|
|
|
|
|
|
#endif /*INCLUDED_C_STRINGLIST_H*/
|