2026-08-29 01:50:50 +08:00
|
|
|
|
#ifndef INCLUDED_C_ARRAY_H
|
|
|
|
|
|
#define INCLUDED_C_ARRAY_H
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_C_TYPES_H
|
|
|
|
|
|
#include <c_Types.h>
|
|
|
|
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
|
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
|
#ifndef INCLUDED_C_ALLOCATOR_H
|
|
|
|
|
|
#include <c_Allocator.h>
|
|
|
|
|
|
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-08-29 01:50:50 +08:00
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
|
|
|
|
/* */
|
|
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
|
typedef struct {
|
|
|
|
|
|
void* array; // 连续的数据存储区(直接密集存储数据值)
|
|
|
|
|
|
c_size_t item_size; // 单个元素的字节大小(例如 sizeof(int))
|
|
|
|
|
|
c_size_t size; // 数组的固定长度(同时也是当前的物理容量)
|
|
|
|
|
|
c_Allocator_t allocator; // 内部绑定的自主内存管理器
|
|
|
|
|
|
} c_Array_t;
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
|
|
|
|
/* */
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
|
c_err_t c_Array_Init(c_Array_t* self, c_size_t item_size, c_size_t size, c_Allocator_t* allocator);
|
|
|
|
|
|
void c_Array_Destroy(c_Array_t* self);
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
|
// 核心固定数组操作 API (安全值复制模式)
|
|
|
|
|
|
c_err_t c_Array_Read(const c_Array_t* self, c_size_t index, void* out_item);
|
|
|
|
|
|
c_err_t c_Array_Write(c_Array_t* self, c_size_t index, const void* item);
|
|
|
|
|
|
void* c_Array_Get(const c_Array_t* self, c_size_t index);
|
|
|
|
|
|
c_err_t c_Array_Fill(c_Array_t* self, const void* item);
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
2026-08-30 01:48:03 +08:00
|
|
|
|
// 内联高频辅助接口
|
|
|
|
|
|
C_STATIC_FORCE_INLINE
|
|
|
|
|
|
c_size_t c_Array_Size(const c_Array_t* self) {
|
|
|
|
|
|
if (!self) return 0;
|
|
|
|
|
|
return self->size; // O(1) 实时读取,固定不变
|
|
|
|
|
|
}
|
2026-08-29 01:50:50 +08:00
|
|
|
|
|
|
|
|
|
|
#endif /*INCLUDED_C_ARRAY_H*/
|