aboutsummaryrefslogtreecommitdiff
path: root/stack.h
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-29 14:52:47 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-29 14:52:47 +0300
commit5e7591a2f684bba637e120497a2ba0fdd3db8dda (patch)
tree344e55bf37a8bae5a31f231108a20bd57a3f4cb8 /stack.h
parent7a69d0103dadc08f228d14b27d38df193044bb29 (diff)
downloadastar-5e7591a2f684bba637e120497a2ba0fdd3db8dda.tar.xz
Make the stack dynamic
Diffstat (limited to 'stack.h')
-rw-r--r--stack.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/stack.h b/stack.h
index 68fdb78..2105c7c 100644
--- a/stack.h
+++ b/stack.h
@@ -4,20 +4,20 @@
#include <stddef.h>
#include "structs.h"
-/* So, the implementation of the stack is array-based, for hyperspeed.
- * For bigger maps we have to increase the STACK_SIZE, but it should
- * work fine most of the time. I guess */
-#define STACK_SIZE 4096
+#define STACK_INITIAL_CAPACITY 4096
+#define STACK_SIZE_COEFFICIENT 2
struct PositionStack_s {
- Position arr[STACK_SIZE]; /* The array with all the values */
+ Position *arr; /* The array with all the values */
+ size_t capacity;
size_t top; /* Shows where the top of the stack is */
};
typedef struct PositionStack_s PositionStack;
PositionStack ps_new(void); /* Returns an empty position stack */
-int ps_push(PositionStack *ps, Position pos); /* Returns -1 if overflow */
+int ps_push(PositionStack *ps, Position pos); /* Returns -1 if failed to realloc() */
Position ps_pop(PositionStack *ps);
Position ps_peek(PositionStack ps);
+void ps_free(PositionStack ps);
#endif /* STACK_H_ */