lazysphere/src/util/stack.h

27 lines
625 B
C
Raw Normal View History

2023-05-02 04:37:30 +00:00
#pragma once
#include <stddef.h>
#include <stdbool.h>
struct Stack {
size_t size;
size_t capacity;
void* data;
};
void stack_init(struct Stack* stack, size_t size);
void stack_push(struct Stack* stack, void* data, size_t len);
void* stack_pop(struct Stack* stack, size_t len);
void stack_free(struct Stack* stack);
inline void stack_push_int(struct Stack* stack, int value) {
stack_push(stack, &value, sizeof(int));
}
inline bool stack_pop_int(struct Stack* stack, int* value) {
void* d = stack_pop(stack, sizeof(int));
if (d == NULL) return false;
*value = *(int*)(d);
return true;
}