From b9006ebb0fe16d7f48d7e0fb9e7a145981eef023 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Wed, 23 Apr 2025 05:08:00 -0500 Subject: [PATCH 1/7] feat(stack): added stack datastructure with init and destroy function --- Include/Fledasty/Core/Stack.h | 40 ++++++++++++++++++++++++ Src/Core/Stack.c | 58 +++++++++++++++++++++++++++++++++++ Tests/Main.c | 6 ++++ 3 files changed, 104 insertions(+) diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index e69de29..78805bf 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -0,0 +1,40 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Stack.h + * Description: + * This file contains the Stack structure and the functions for modifying it. + * It includes functions to Push, Pop, Peek and check if empty. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef FLEDASTY_STACK +#define FLEDASTY_STACK + +#include + +#include "../Utils/Error.h" + +typedef struct { + size_t size, capacity; + + size_t element_byte_size; + unsigned char *buffer; +} FledastyStack; + +FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size); +FledastyError fledasty_stack_destroy(FledastyStack *current_stack); + +#endif \ No newline at end of file diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index e69de29..1938d7a 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -0,0 +1,58 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Stack.c + * Description: + * This file contains the functions for modifying the stack. It includes functions + * to Push, Pop, Peek and check if empty. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#include "../../Include/Fledasty/Core/Stack.h" + +#include +#include +#include + +FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size) { + if (new_stack == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + new_stack->size = 0; + new_stack->capacity = 10; + new_stack->element_byte_size = element_byte_size; + + new_stack->buffer = (unsigned char*)hallocy_malloc(new_stack->capacity * element_byte_size); + if (new_stack->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + + return FLEDASTY_ERROR_NONE; +} + +FledastyError fledasty_stack_destroy(FledastyStack *current_stack) { + if (current_stack == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + HallocyError result = hallocy_free(current_stack->buffer); + if (result != HALLOCY_ERROR_NONE) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + + current_stack->buffer = NULL; + return FLEDASTY_ERROR_NONE; +} \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index 1097b69..33ab88a 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -21,6 +21,7 @@ */ #include #include +#include int main() { FledastyQueue test_queue; @@ -44,6 +45,11 @@ int main() { fledasty_queue_destroy(&test_queue); + FledastyStack test_stack; + fledasty_stack_initialize(&test_stack, sizeof(int)); + + fledasty_stack_destroy(&test_stack); + printf("Done\n"); return 0; } \ No newline at end of file From 47f7db53bb74955839fbec66cc966f83be9f24dc Mon Sep 17 00:00:00 2001 From: Mineplay Date: Wed, 23 Apr 2025 05:11:25 -0500 Subject: [PATCH 2/7] feat(stack): added is empty function to stack --- Include/Fledasty/Core/Queue.h | 2 +- Include/Fledasty/Core/Stack.h | 2 ++ Tests/Main.c | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index 8b168fc..a874f91 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -42,6 +42,6 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); void *fledasty_queue_peek(FledastyQueue *current_queue); void *fledasty_queue_pop(FledastyQueue *current_queue); -static inline size_t fledasty_queue_is_empty(FledastyQueue *current_queue) { return current_queue->size == 0; } +static inline size_t fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue->size == 0; } #endif \ No newline at end of file diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index 78805bf..c3977a6 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -37,4 +37,6 @@ typedef struct { FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size); FledastyError fledasty_stack_destroy(FledastyStack *current_stack); +static inline size_t fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; } + #endif \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index 33ab88a..7a53313 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -48,6 +48,10 @@ int main() { FledastyStack test_stack; fledasty_stack_initialize(&test_stack, sizeof(int)); + if (fledasty_stack_is_empty(&test_stack)) { + printf("Stack is empty\n"); + } + fledasty_stack_destroy(&test_stack); printf("Done\n"); From 0e430f3dd52e57d19ac6defa823d0a2f4dd86270 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Wed, 23 Apr 2025 05:33:10 -0500 Subject: [PATCH 3/7] feat(stack): added push function to stack --- Include/Fledasty/Core/Stack.h | 2 ++ Src/Core/Stack.c | 20 ++++++++++++++++++++ Tests/Main.c | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index c3977a6..d117836 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -37,6 +37,8 @@ typedef struct { FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size); FledastyError fledasty_stack_destroy(FledastyStack *current_stack); +FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value); + static inline size_t fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; } #endif \ No newline at end of file diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index 1938d7a..6c6090c 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -54,5 +54,25 @@ FledastyError fledasty_stack_destroy(FledastyStack *current_stack) { } current_stack->buffer = NULL; + return FLEDASTY_ERROR_NONE; +} + +FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value) { + if (current_stack == NULL || value == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + if (current_stack->size == current_stack->capacity) { + current_stack->capacity = current_stack->capacity + (current_stack->capacity / 2); + current_stack->buffer = (unsigned char*)hallocy_realloc(current_stack->buffer, current_stack->capacity); + + if (current_stack->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + } + + hallocy_copy_memory(current_stack->buffer + (current_stack->size * current_stack->element_byte_size), value, current_stack->element_byte_size); + current_stack->size += 1; + return FLEDASTY_ERROR_NONE; } \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index 7a53313..b31e9fa 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -48,6 +48,10 @@ int main() { FledastyStack test_stack; fledasty_stack_initialize(&test_stack, sizeof(int)); + for (int i = 0; i < 10; i += 1) { + fledasty_stack_push(&test_stack, &i); + } + if (fledasty_stack_is_empty(&test_stack)) { printf("Stack is empty\n"); } From 01ce91cfa4c38ab4479eb5aeb172f7a053078784 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Wed, 23 Apr 2025 07:14:45 -0500 Subject: [PATCH 4/7] feat(stack): implemented peek function for stack --- Include/Fledasty/Core/Stack.h | 1 + Src/Core/Stack.c | 10 +++++++++- Tests/Main.c | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index d117836..7438ecf 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -38,6 +38,7 @@ FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t e FledastyError fledasty_stack_destroy(FledastyStack *current_stack); FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value); +void *fledasty_stack_peek(FledastyStack *current_stack); static inline size_t fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; } diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index 6c6090c..71e3a11 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -73,6 +73,14 @@ FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value) { hallocy_copy_memory(current_stack->buffer + (current_stack->size * current_stack->element_byte_size), value, current_stack->element_byte_size); current_stack->size += 1; - + return FLEDASTY_ERROR_NONE; +} + +void *fledasty_stack_peek(FledastyStack *current_stack) { + if (current_stack == NULL) { + return NULL; + } + + return current_stack->buffer + ((current_stack->size - 1) * current_stack->element_byte_size); } \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index b31e9fa..c0dca96 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -31,8 +31,8 @@ int main() { fledasty_queue_push(&test_queue, &i); } - int *peek_data = (int*)fledasty_queue_peek(&test_queue); - printf("Peeked: %d\n", *peek_data); + int *peeked_queue_data = (int*)fledasty_queue_peek(&test_queue); + printf("Peeked: %d\n", *peeked_queue_data); for (int i = test_queue.size; i > 0; i -= 1) { int *popped_data = (int*)fledasty_queue_pop(&test_queue); @@ -52,6 +52,9 @@ int main() { fledasty_stack_push(&test_stack, &i); } + int *peeked_stack_data = (int*)fledasty_stack_peek(&test_stack); + printf("Peeked: %d\n", *peeked_stack_data); + if (fledasty_stack_is_empty(&test_stack)) { printf("Stack is empty\n"); } From 8b0a617cb80a59d3cfaf4396620dad024a2eb0d8 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Wed, 23 Apr 2025 12:05:36 -0500 Subject: [PATCH 5/7] feat(stack): implemented pop function for stack --- Include/Fledasty/Core/Queue.h | 2 +- Include/Fledasty/Core/Stack.h | 3 ++- Src/Core/Queue.c | 2 +- Src/Core/Stack.c | 13 ++++++++++++- Tests/Main.c | 5 +++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index a874f91..762262f 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -39,7 +39,7 @@ FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, const size_t e FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); -void *fledasty_queue_peek(FledastyQueue *current_queue); +void *fledasty_queue_peek(const FledastyQueue *current_queue); void *fledasty_queue_pop(FledastyQueue *current_queue); static inline size_t fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue->size == 0; } diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index 7438ecf..bcf0a97 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -38,7 +38,8 @@ FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t e FledastyError fledasty_stack_destroy(FledastyStack *current_stack); FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value); -void *fledasty_stack_peek(FledastyStack *current_stack); +void *fledasty_stack_peek(const FledastyStack *current_stack); +void *fledasty_stack_pop(FledastyStack *current_stack); static inline size_t fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; } diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c index e076b46..37d44c1 100644 --- a/Src/Core/Queue.c +++ b/Src/Core/Queue.c @@ -89,7 +89,7 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) { return FLEDASTY_ERROR_NONE; } -void *fledasty_queue_peek(FledastyQueue *current_queue) { +void *fledasty_queue_peek(const FledastyQueue *current_queue) { if (current_queue == NULL) { return NULL; } diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index 71e3a11..4a377c0 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -77,10 +77,21 @@ FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value) { return FLEDASTY_ERROR_NONE; } -void *fledasty_stack_peek(FledastyStack *current_stack) { +void *fledasty_stack_peek(const FledastyStack *current_stack) { if (current_stack == NULL) { return NULL; } return current_stack->buffer + ((current_stack->size - 1) * current_stack->element_byte_size); +} + +void *fledasty_stack_pop(FledastyStack *current_stack) { + if (current_stack == NULL) { + return NULL; + } + + void *value_address = current_stack->buffer + ((current_stack->size - 1) * current_stack->element_byte_size); + current_stack->size -= 1; + + return value_address; } \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index c0dca96..933fd43 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -55,6 +55,11 @@ int main() { int *peeked_stack_data = (int*)fledasty_stack_peek(&test_stack); printf("Peeked: %d\n", *peeked_stack_data); + for (int i = test_stack.size; i > 0; i -= 1) { + int *popped_data = (int*)fledasty_stack_pop(&test_stack); + printf("Popped: %d\n", *popped_data); + } + if (fledasty_stack_is_empty(&test_stack)) { printf("Stack is empty\n"); } From 6e8b2eade39e4f7911aa2c80380aa36deb18e900 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Wed, 23 Apr 2025 17:40:38 -0500 Subject: [PATCH 6/7] feat(stack): made it possible to initialize stack with list --- Include/Fledasty/Core/Stack.h | 2 +- Src/Core/Stack.c | 24 ++++++++++++++++++------ Tests/Main.c | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index bcf0a97..fc0d237 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -34,7 +34,7 @@ typedef struct { unsigned char *buffer; } FledastyStack; -FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size); +FledastyError fledasty_stack_initialize(FledastyStack *new_stack, void *values, const size_t values_size, const size_t element_byte_size); FledastyError fledasty_stack_destroy(FledastyStack *current_stack); FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value); diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index 4a377c0..f59775c 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -26,18 +26,30 @@ #include #include -FledastyError fledasty_stack_initialize(FledastyStack *new_stack, const size_t element_byte_size) { +FledastyError fledasty_stack_initialize(FledastyStack *new_stack, void *values, const size_t values_size, const size_t element_byte_size) { if (new_stack == NULL) { return FLEDASTY_ERROR_INVALID_POINTER; } - new_stack->size = 0; - new_stack->capacity = 10; new_stack->element_byte_size = element_byte_size; + if (values == NULL || values_size == 0) { + new_stack->size = 0; + new_stack->capacity = 10; - new_stack->buffer = (unsigned char*)hallocy_malloc(new_stack->capacity * element_byte_size); - if (new_stack->buffer == NULL) { - return FLEDASTY_ERROR_FAILED_ALLOCATION; + new_stack->buffer = (unsigned char*)hallocy_malloc(new_stack->capacity * element_byte_size); + if (new_stack->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + } else { + new_stack->size = values_size; + new_stack->capacity = values_size + (values_size / 2); + + new_stack->buffer = (unsigned char*)hallocy_malloc(new_stack->capacity * element_byte_size); + if (new_stack->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + + hallocy_copy_memory(new_stack->buffer, values, values_size * element_byte_size); } return FLEDASTY_ERROR_NONE; diff --git a/Tests/Main.c b/Tests/Main.c index 933fd43..8a4b193 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -46,7 +46,7 @@ int main() { fledasty_queue_destroy(&test_queue); FledastyStack test_stack; - fledasty_stack_initialize(&test_stack, sizeof(int)); + fledasty_stack_initialize(&test_stack, (int[]){ 11, 12, 13, 14, 15 }, 5, sizeof(int)); for (int i = 0; i < 10; i += 1) { fledasty_stack_push(&test_stack, &i); From c24d41f41920c78c857f90d3e80f5eb41bdc1795 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Thu, 24 Apr 2025 04:49:52 -0500 Subject: [PATCH 7/7] fix(queue): fixed reallocation issue and made init of queue consistent with stack --- Include/Fledasty/Core/Queue.h | 2 +- Src/Core/Queue.c | 40 +++++++++++++++++++++++------------ Src/Core/Stack.c | 2 +- Tests/Main.c | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index 762262f..2775230 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -35,7 +35,7 @@ typedef struct { unsigned char *buffer; } FledastyQueue; -FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, const size_t element_byte_size); +FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, void *values, const size_t values_size, const size_t element_byte_size); FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c index 37d44c1..f06898e 100644 --- a/Src/Core/Queue.c +++ b/Src/Core/Queue.c @@ -26,23 +26,35 @@ #include #include -FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, const size_t element_byte_size) { +FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, void *values, const size_t values_size, const size_t element_byte_size) { if (new_queue == NULL) { return FLEDASTY_ERROR_INVALID_POINTER; } - new_queue->size = 0; - new_queue->capacity = 10; + new_queue->head = 0; new_queue->element_byte_size = element_byte_size; + if (values == NULL || values_size == 0) { + new_queue->size = 0; + new_queue->capacity = 10; - new_queue->buffer = (unsigned char*)hallocy_malloc(new_queue->capacity * element_byte_size); - if (new_queue->buffer == NULL) { - return FLEDASTY_ERROR_FAILED_ALLOCATION; + new_queue->buffer = (unsigned char*)hallocy_malloc(new_queue->capacity * element_byte_size); + if (new_queue->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + } else { + new_queue->size = values_size; + new_queue->capacity = values_size + (values_size / 2); + + new_queue->buffer = (unsigned char*)hallocy_malloc(new_queue->capacity * element_byte_size); + if (new_queue->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + + hallocy_copy_memory(new_queue->buffer, values, values_size * element_byte_size); } - new_queue->head = 0; - new_queue->tail = 0; - + new_queue->tail = new_queue->size; + return FLEDASTY_ERROR_NONE; } @@ -66,15 +78,16 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) { } if (current_queue->size == current_queue->capacity) { - current_queue->capacity = current_queue->capacity + (current_queue->capacity / 2); + current_queue->capacity += current_queue->capacity; current_queue->buffer = (unsigned char*)hallocy_realloc(current_queue->buffer, current_queue->capacity * current_queue->element_byte_size); if (current_queue->buffer == NULL) { return FLEDASTY_ERROR_FAILED_ALLOCATION; } - size_t new_head = current_queue->capacity - current_queue->head; - hallocy_move_memory(current_queue->buffer + (current_queue->head * current_queue->element_byte_size), current_queue->buffer + (new_head * current_queue->element_byte_size), current_queue->size - current_queue->tail); + size_t head_length = current_queue->size - current_queue->head; + size_t new_head = current_queue->capacity - head_length; + hallocy_move_memory(current_queue->buffer + (new_head * current_queue->element_byte_size), current_queue->buffer + (current_queue->head * current_queue->element_byte_size), head_length * current_queue->element_byte_size); current_queue->head = new_head; } @@ -105,10 +118,9 @@ void *fledasty_queue_pop(FledastyQueue *current_queue) { void *value_address = current_queue->buffer + (current_queue->head * current_queue->element_byte_size); current_queue->size -= 1; + current_queue->head += 1; if (current_queue->head == current_queue->capacity) { current_queue->head = 0; - } else { - current_queue->head += 1; } return value_address; diff --git a/Src/Core/Stack.c b/Src/Core/Stack.c index f59775c..b35b517 100644 --- a/Src/Core/Stack.c +++ b/Src/Core/Stack.c @@ -75,7 +75,7 @@ FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value) { } if (current_stack->size == current_stack->capacity) { - current_stack->capacity = current_stack->capacity + (current_stack->capacity / 2); + current_stack->capacity += current_stack->capacity; current_stack->buffer = (unsigned char*)hallocy_realloc(current_stack->buffer, current_stack->capacity); if (current_stack->buffer == NULL) { diff --git a/Tests/Main.c b/Tests/Main.c index 8a4b193..383bf48 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -25,7 +25,7 @@ int main() { FledastyQueue test_queue; - fledasty_queue_initialize(&test_queue, sizeof(int)); + fledasty_queue_initialize(&test_queue, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int)); for (int i = 0; i < 10; i += 1) { fledasty_queue_push(&test_queue, &i);