summaryrefslogtreecommitdiff
path: root/src/util/stack.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-06 00:39:44 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-06 00:39:44 -0400
commitd8f2c10b7108fff6b7e437291093a1cadc15ab9f (patch)
tree3fc50a19d6fbb9c94a8fe147cd2a6c4ba7f59b8d /src/util/stack.c
parentansii c (diff)
downloadlazysphere-d8f2c10b7108fff6b7e437291093a1cadc15ab9f.tar.gz
lazysphere-d8f2c10b7108fff6b7e437291093a1cadc15ab9f.tar.bz2
lazysphere-d8f2c10b7108fff6b7e437291093a1cadc15ab9f.zip
refactor
Diffstat (limited to 'src/util/stack.c')
-rw-r--r--src/util/stack.c43
1 files changed, 0 insertions, 43 deletions
diff --git a/src/util/stack.c b/src/util/stack.c
deleted file mode 100644
index acffc1a..0000000
--- a/src/util/stack.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include "stack.h"
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-void stack_init(struct Stack* stack, size_t size) {
- stack->size = 0;
- stack->capacity = size;
- stack->data = malloc(size);
-}
-
-void stack_push(struct Stack* stack, void* data, size_t len) {
- size_t new_size = stack->size + len;
- if (new_size >= stack->capacity) {
- stack->capacity = new_size * 2;
- stack->data = realloc(stack->data, stack->capacity);
- }
- memcpy((uint8_t*)stack->data + stack->size, data, len);
- stack->size += len;
-}
-
-void* stack_pop(struct Stack* stack, size_t len) {
- if (stack->size < len) return NULL;
- stack->size -= len;
- return (uint8_t*)stack->data + stack->size;
-}
-
-void stack_free(struct Stack *stack) {
- free(stack->data);
-}
-
-void stack_push_int(struct Stack *stack, int value) {
- stack_push(stack, &value, sizeof(int));
-}
-
-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;
-}