Files

54 lines
1.8 KiB
C
Raw Permalink Normal View History

2026-08-30 03:59:45 +08:00
#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;
2026-08-31 22:49:42 +08:00
} c_StringList_t;
2026-08-30 03:59:45 +08:00
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
2026-08-31 22:49:42 +08:00
c_err_t c_StringList_Init(c_StringList_t* self, c_size_t capacity, c_Allocator_t* allocator);
void c_StringList_Destroy(c_StringList_t* self);
2026-08-30 03:59:45 +08:00
// 核心操作 API (安全深拷贝值复制模式)
2026-08-31 22:49:42 +08:00
c_err_t c_StringList_Add(c_StringList_t* self, const char* str);
c_err_t c_StringList_InsertAt(c_StringList_t* self, c_size_t index, const char* str);
c_err_t c_StringList_RemoveAt(c_StringList_t* self, c_size_t index);
void c_StringList_Clear(c_StringList_t* self);
2026-08-30 03:59:45 +08:00
// 高级功能接口
2026-08-31 22:49:42 +08:00
c_err_t c_StringList_Clone(c_StringList_t* dest, const c_StringList_t* src);
c_err_t c_StringList_Deduplicate(c_StringList_t* self);
2026-08-30 03:59:45 +08:00
// 极致高频内联只读窥探接口
2026-08-30 13:01:05 +08:00
C_STATIC_FORCE_INLINE
2026-08-31 22:49:42 +08:00
c_size_t c_StringList_Size(const c_StringList_t* self) {
2026-08-30 03:59:45 +08:00
return self ? self->size : 0; // O(1) 实时读取
}
2026-08-30 13:01:05 +08:00
C_STATIC_FORCE_INLINE
2026-08-31 22:49:42 +08:00
const char* c_StringList_Get(const c_StringList_t* self, c_size_t index) {
2026-08-30 03:59:45 +08:00
if (!self || index >= self->size || !self->strings) return NULL;
return self->strings[index]; // 零拷贝原位返回
}
#endif /*INCLUDED_C_STRINGLIST_H*/