Files

46 lines
1.6 KiB
C
Raw Permalink Normal View History

2026-08-29 01:50:50 +08:00
#ifndef INCLUDED_C_ARRAYSTACK_H
#define INCLUDED_C_ARRAYSTACK_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
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
typedef struct {
2026-08-30 01:48:03 +08:00
void* array; // 连续的数据存储区(直接存储数据值)
c_size_t item_size; // 单个元素的字节大小(例如 sizeof(int)
c_size_t capacity; // 当前栈的最大可容纳容量
c_size_t size; // 当前栈内的元素个数(同时也是下一个入栈元素的索引位置)
c_Allocator_t allocator; // 绑定的内存管理器
2026-08-29 01:50:50 +08:00
} c_ArrayStack_t;
2026-08-30 01:48:03 +08:00
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_err_t c_ArrayStack_Init(c_ArrayStack_t* self, c_size_t item_size, c_size_t capacity, c_Allocator_t* allocator);
2026-08-29 01:50:50 +08:00
void c_ArrayStack_Destroy(c_ArrayStack_t* self);
2026-08-30 01:48:03 +08:00
c_err_t c_ArrayStack_Resize(c_ArrayStack_t* self, c_size_t new_capacity);
c_err_t c_ArrayStack_Push(c_ArrayStack_t* self, const void* item);
c_err_t c_ArrayStack_Pop(c_ArrayStack_t* self, void* out_item) ;
void* c_ArrayStack_Peek(const c_ArrayStack_t* self);
2026-08-29 01:50:50 +08:00
C_STATIC_FORCE_INLINE
2026-08-30 01:48:03 +08:00
c_size_t c_ArrayStack_Size(const c_ArrayStack_t* self) {
if (!self) return 0;
return self->size;
}
C_STATIC_FORCE_INLINE
bool c_ArrayStack_IsEmpty(const c_ArrayStack_t* self) {
return c_ArrayStack_Size(self) == 0;
2026-08-29 01:50:50 +08:00
}
#endif /*INCLUDED_C_ARRAYSTACK_H*/