Compare commits

...

2 commits

6 changed files with 231 additions and 355 deletions

View file

@ -25,27 +25,135 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <Hallocy/Core/Allocator.h>
#include <Hallocy/Core/Memory.h>
#include <Hallocy/Utils/Error.h>
#include "../Utils/Error.h" #include "../Utils/Error.h"
typedef struct { #define FLEDASTY_QUEUE_DEFINE(type) \
size_t size, capacity; typedef struct { \
size_t head, tail; size_t size, capacity; \
size_t head, tail; \
type *buffer; \
} FledastyQueue_##type; \
\
FledastyError fledasty_queue_##type##_free(FledastyQueue_##type *current_queue); \
\
FledastyError fledasty_queue_##type##_push(FledastyQueue_##type *current_queue, type value); \
type fledasty_queue_##type##_pop(FledastyQueue_##type *current_queue); \
\
FledastyError fledasty_queue_##type##_clear(FledastyQueue_##type *current_queue); \
FledastyError fledasty_queue_##type##_shrink_to_fit(FledastyQueue_##type *current_queue); \
\
static inline type fledasty_queue_##type##_peek(const FledastyQueue_##type *current_queue) { return (current_queue != NULL && current_queue->size > 0) ? current_queue->buffer[current_queue->size - 1] : 0; } \
static inline bool fledasty_queue_##type##_is_empty(const FledastyQueue_##type *current_queue) { return current_queue == NULL || current_queue->size == 0; }
size_t element_byte_size; #define FLEDASTY_QUEUE_IMPLEMENT(type) \
unsigned char *buffer; FledastyError fledasty_queue_##type##_free(FledastyQueue_##type *current_queue) { \
} FledastyQueue; if (current_queue == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
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); \
if (hallocy_free(current_queue->buffer) != HALLOCY_ERROR_NONE) { \
FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); return FLEDASTY_ERROR_FAILED_ALLOCATION; \
void *fledasty_queue_pop(FledastyQueue *current_queue); } \
\
FledastyError fledasty_queue_clear(FledastyQueue *current_queue); current_queue->size = 0; \
FledastyError fledasty_queue_shrink_to_fit(FledastyQueue *current_queue); current_queue->capacity = 0; \
current_queue->buffer = NULL; \
static inline void *fledasty_queue_peek(const FledastyQueue *current_queue) { return (current_queue == NULL) ? NULL : current_queue->buffer + (current_queue->head * current_queue->element_byte_size); } \
static inline bool fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue == NULL || current_queue->size == 0; } return FLEDASTY_ERROR_NONE; \
} \
\
FledastyError fledasty_queue_##type##_push(FledastyQueue_##type *current_queue, type value) { \
if (current_queue == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
} \
\
if (current_queue->size == current_queue->capacity) { \
current_queue->capacity += current_queue->capacity ? current_queue->capacity : 16; \
current_queue->buffer = (type*)hallocy_realloc(current_queue->buffer, current_queue->capacity * sizeof(type)); \
\
if (current_queue->buffer == NULL) { \
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
} \
\
if (current_queue->tail < current_queue->head) { \
size_t head_size = current_queue->size - current_queue->tail; \
\
hallocy_move_memory(current_queue->buffer, current_queue->buffer + current_queue->head, head_size * sizeof(type)); \
hallocy_move_memory(current_queue->buffer + head_size, current_queue->buffer, current_queue->tail * sizeof(type)); \
} else { \
hallocy_move_memory(current_queue->buffer, current_queue->buffer + current_queue->head, current_queue->size * sizeof(type)); \
} \
\
current_queue->head = 0; \
current_queue->tail = current_queue->size; \
} \
\
current_queue->buffer[current_queue->tail++] = value; \
if (current_queue->tail >= current_queue->capacity) { \
current_queue->tail = 0; \
} \
\
current_queue->size += 1; \
return FLEDASTY_ERROR_NONE; \
} \
\
type fledasty_queue_##type##_pop(FledastyQueue_##type *current_queue) { \
if (current_queue == NULL || current_queue->size == 0) { \
return 0; \
} \
\
current_queue->size -= 1; \
current_queue->head += 1; \
if (current_queue->head == current_queue->capacity) { \
current_queue->head = 0; \
} \
\
return current_queue->buffer[current_queue->head - 1]; \
} \
\
FledastyError fledasty_queue_##type##_clear(FledastyQueue_##type *current_queue) { \
if (current_queue == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
} \
\
current_queue->size = 0; \
return FLEDASTY_ERROR_NONE; \
} \
\
FledastyError fledasty_queue_##type##_shrink_to_fit(FledastyQueue_##type *current_queue) { \
if (current_queue == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
} \
\
size_t new_capacity = (current_queue->size == 0) ? 16 : current_queue->size; \
type *shrinked_buffer = (type*)hallocy_malloc(new_capacity * sizeof(type)); \
if (shrinked_buffer == NULL) { \
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
} \
\
if (current_queue->tail < current_queue->head) { \
size_t head_size = current_queue->size - current_queue->tail; \
\
hallocy_copy_memory(shrinked_buffer, current_queue->buffer + current_queue->head, head_size * sizeof(type)); \
hallocy_copy_memory(shrinked_buffer + head_size, current_queue->buffer, current_queue->tail * sizeof(type)); \
} else { \
hallocy_copy_memory(shrinked_buffer, current_queue->buffer + current_queue->head, current_queue->size * sizeof(type)); \
} \
\
if (hallocy_free(current_queue->buffer) != HALLOCY_ERROR_NONE) { \
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
} \
\
current_queue->head = 0; \
current_queue->tail = current_queue->size; \
current_queue->capacity = new_capacity; \
current_queue->buffer = shrinked_buffer; \
\
return FLEDASTY_ERROR_NONE; \
}
#endif #endif

View file

@ -25,26 +25,91 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <Hallocy/Core/Allocator.h>
#include <Hallocy/Core/Memory.h>
#include <Hallocy/Utils/Error.h>
#include "../Utils/Error.h" #include "../Utils/Error.h"
typedef struct { #define FLEDASTY_STACK_DEFINE(type) \
size_t size, capacity; typedef struct { \
size_t size, capacity; \
type *buffer; \
} FledastyStack_##type; \
\
FledastyError fledasty_stack_##type##_free(FledastyStack_##type *current_stack); \
\
FledastyError fledasty_stack_##type##_push(FledastyStack_##type *current_stack, type value); \
\
FledastyError fledasty_stack_##type##_clear(FledastyStack_##type *current_stack); \
FledastyError fledasty_stack_##type##_shrink_to_fit(FledastyStack_##type *current_stack); \
\
static inline type fledasty_stack_##type##_pop(FledastyStack_##type *current_stack) { return (current_stack != NULL && current_stack->size > 0) ? current_stack->buffer[--current_stack->size] : 0; } \
static inline type fledasty_stack_##type##_peek(const FledastyStack_##type *current_stack) { return (current_stack != NULL && current_stack->size > 0) ? current_stack->buffer[current_stack->size - 1] : 0; } \
static inline bool fledasty_stack_##type##_is_empty(const FledastyStack_##type *current_stack) { return current_stack == NULL || current_stack->size == 0; }
size_t element_byte_size; #define FLEDASTY_STACK_IMPLEMENT(type) \
unsigned char *buffer; FledastyError fledasty_stack_##type##_free(FledastyStack_##type *current_stack) { \
} FledastyStack; if (current_stack == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
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); \
if (hallocy_free(current_stack->buffer) != HALLOCY_ERROR_NONE) { \
FledastyError fledasty_stack_push(FledastyStack *current_stack, void *value); return FLEDASTY_ERROR_FAILED_ALLOCATION; \
void *fledasty_stack_pop(FledastyStack *current_stack); } \
\
FledastyError fledasty_stack_clear(FledastyStack *current_stack); current_stack->size = 0; \
FledastyError fledasty_stack_shrink_to_fit(FledastyStack *current_stack); current_stack->capacity = 0; \
current_stack->buffer = NULL; \
static inline void *fledasty_stack_peek(const FledastyStack *current_stack) { return (current_stack == NULL) ? NULL : current_stack->buffer + ((current_stack->size - 1) * current_stack->element_byte_size); } \
static inline bool fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack == NULL || current_stack->size == 0; } return FLEDASTY_ERROR_NONE; \
} \
\
FledastyError fledasty_stack_##type##_push(FledastyStack_##type *current_stack, type value) { \
if (current_stack == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
} \
\
if (current_stack->size == current_stack->capacity) { \
current_stack->capacity += current_stack->capacity ? current_stack->capacity : 16; \
current_stack->buffer = (type*)hallocy_realloc(current_stack->buffer, current_stack->capacity * sizeof(type)); \
\
if (current_stack->buffer == NULL) { \
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
} \
} \
\
current_stack->buffer[current_stack->size++] = value; \
return FLEDASTY_ERROR_NONE; \
} \
\
FledastyError fledasty_stack_##type##_clear(FledastyStack_##type *current_stack) { \
if (current_stack == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
} \
\
current_stack->size = 0; \
return FLEDASTY_ERROR_NONE; \
} \
\
FledastyError fledasty_stack_##type##_shrink_to_fit(FledastyStack_##type *current_stack) { \
if (current_stack == NULL) { \
return FLEDASTY_ERROR_INVALID_POINTER; \
} \
\
current_stack->capacity = (current_stack->size == 0) ? 10 : current_stack->size; \
type *shrinked_buffer = (type*)hallocy_malloc(current_stack->capacity * sizeof(type)); \
if (shrinked_buffer == NULL) { \
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
} \
\
hallocy_copy_memory(shrinked_buffer, current_stack->buffer, current_stack->size * sizeof(type)); \
if (hallocy_free(current_stack->buffer) != HALLOCY_ERROR_NONE) { \
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
} \
\
current_stack->buffer = shrinked_buffer; \
return FLEDASTY_ERROR_NONE; \
}
#endif #endif

View file

@ -23,7 +23,6 @@
#include "../../Include/Fledasty/Algorithms/Hashing.h" #include "../../Include/Fledasty/Algorithms/Hashing.h"
#include <Hallocy/Core/Memory.h> #include <Hallocy/Core/Memory.h>
#include <stdint.h>
static inline uint32_t fledasty_rolt_32(const uint32_t key, const uint32_t rotation) { return (key << rotation) | (key >> (32 - rotation)); } static inline uint32_t fledasty_rolt_32(const uint32_t key, const uint32_t rotation) { return (key << rotation) | (key >> (32 - rotation)); }
static inline uint64_t fledasty_rolt_64(uint64_t key, const uint64_t rotation) { return (key << rotation) | (key >> (64 - rotation)); } static inline uint64_t fledasty_rolt_64(uint64_t key, const uint64_t rotation) { return (key << rotation) | (key >> (64 - rotation)); }

View file

@ -1,165 +0,0 @@
/*
* 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: Queue.c
* Description:
* This file contains the functions for modifying the queue. It includes functions
* to Push, Pop, Peek and check if empty.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#include "../../Include/Fledasty/Core/Queue.h"
#include <Hallocy/Core/Allocator.h>
#include <Hallocy/Core/Memory.h>
#include <Hallocy/Utils/Error.h>
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->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;
}
} else {
new_queue->size = values_size;
new_queue->capacity = new_queue->size + new_queue->size;
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->tail = new_queue->size;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) {
if (current_queue == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
if (hallocy_free(current_queue->buffer) != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
current_queue->buffer = NULL;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) {
if (current_queue == NULL || value == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
if (current_queue->size == current_queue->capacity) {
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;
}
if (current_queue->tail < current_queue->head) {
size_t head_size = (current_queue->size - current_queue->tail) * current_queue->element_byte_size;
hallocy_move_memory(current_queue->buffer, current_queue->buffer + (current_queue->head * current_queue->element_byte_size), head_size);
hallocy_move_memory(current_queue->buffer + head_size, current_queue->buffer, current_queue->tail * current_queue->element_byte_size);
} else {
hallocy_move_memory(current_queue->buffer, current_queue->buffer + (current_queue->head * current_queue->element_byte_size), current_queue->size * current_queue->element_byte_size);
}
current_queue->head = 0;
current_queue->tail = current_queue->size;
}
hallocy_copy_memory(current_queue->buffer + (current_queue->tail * current_queue->element_byte_size), value, current_queue->element_byte_size);
current_queue->size += 1;
current_queue->tail += 1;
if (current_queue->tail >= current_queue->capacity) {
current_queue->tail = 0;
}
return FLEDASTY_ERROR_NONE;
}
void *fledasty_queue_pop(FledastyQueue *current_queue) {
if (current_queue == NULL || current_queue->size == 0) {
return NULL;
}
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;
}
return value_address;
}
FledastyError fledasty_queue_clear(FledastyQueue *current_queue) {
if (current_queue == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
current_queue->size = 0;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_queue_shrink_to_fit(FledastyQueue *current_queue) {
if (current_queue == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
size_t new_capacity = (current_queue->size == 0) ? 10 : current_queue->size;
unsigned char *shrinked_buffer = (unsigned char*)hallocy_malloc(new_capacity);
if (shrinked_buffer == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
if (current_queue->tail < current_queue->head) {
size_t head_size = (current_queue->size - current_queue->tail) * current_queue->element_byte_size;
hallocy_copy_memory(shrinked_buffer, current_queue->buffer + (current_queue->head * current_queue->element_byte_size), head_size);
hallocy_copy_memory(shrinked_buffer + head_size, current_queue->buffer, current_queue->tail * current_queue->element_byte_size);
} else {
hallocy_copy_memory(shrinked_buffer, current_queue->buffer + (current_queue->head * current_queue->element_byte_size), current_queue->size * current_queue->element_byte_size);
}
if (hallocy_free(current_queue->buffer) != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
current_queue->head = 0;
current_queue->tail = current_queue->size;
current_queue->capacity = new_capacity;
current_queue->buffer = shrinked_buffer;
return FLEDASTY_ERROR_NONE;
}

View file

@ -1,127 +0,0 @@
/*
* 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 <Hallocy/Core/Allocator.h>
#include <Hallocy/Core/Memory.h>
#include <Hallocy/Utils/Error.h>
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->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;
}
} else {
new_stack->size = values_size;
new_stack->capacity = new_stack->size + new_stack->size;
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;
}
FledastyError fledasty_stack_destroy(FledastyStack *current_stack) {
if (current_stack == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
if (hallocy_free(current_stack->buffer) != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
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->buffer = (unsigned char*)hallocy_realloc(current_stack->buffer, current_stack->capacity * current_stack->element_byte_size);
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;
}
void *fledasty_stack_pop(FledastyStack *current_stack) {
if (current_stack == NULL) {
return NULL;
}
current_stack->size -= 1;
return current_stack->buffer + (current_stack->size * current_stack->element_byte_size);
}
FledastyError fledasty_stack_clear(FledastyStack *current_stack) {
if (current_stack == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
current_stack->size = 0;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_stack_shrink_to_fit(FledastyStack *current_stack) {
if (current_stack == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
current_stack->capacity = (current_stack->size == 0) ? 10 : current_stack->size;
unsigned char *shrinked_buffer = (unsigned char*)hallocy_malloc(current_stack->capacity * current_stack->element_byte_size);
if (shrinked_buffer == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
hallocy_copy_memory(shrinked_buffer, current_stack->buffer, current_stack->size * current_stack->element_byte_size);
if (hallocy_free(current_stack->buffer) != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
current_stack->buffer = shrinked_buffer;
return FLEDASTY_ERROR_NONE;
}

View file

@ -30,59 +30,55 @@
#include <Fledasty/Strings/UTF8String.h> #include <Fledasty/Strings/UTF8String.h>
#include <Fledasty/Algorithms/Hashing.h> #include <Fledasty/Algorithms/Hashing.h>
FLEDASTY_STACK_DEFINE(int)
FLEDASTY_STACK_IMPLEMENT(int)
FLEDASTY_QUEUE_DEFINE(int)
FLEDASTY_QUEUE_IMPLEMENT(int)
static inline size_t integer_hash_function(const void *key) { return *(int*)key; } static inline size_t integer_hash_function(const void *key) { return *(int*)key; }
int main() { int main() {
FledastyQueue test_queue; FledastyQueue_int test_queue = { 0, 0, 0, 0, NULL };
fledasty_queue_initialize(&test_queue, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));
for (int i = 0; i < 10; i += 1) { for (int i = 0; i < 10; i += 1) {
fledasty_queue_push(&test_queue, &i); fledasty_queue_int_push(&test_queue, i);
} }
fledasty_queue_shrink_to_fit(&test_queue); fledasty_queue_int_shrink_to_fit(&test_queue);
printf("Queue schrinked to fit %s\n", (test_queue.capacity == test_queue.size) ? "succeeded" : "failed"); printf("Queue schrinked to fit %s\n", (test_queue.capacity == test_queue.size) ? "succeeded" : "failed");
int test = 0; fledasty_queue_int_push(&test_queue, 0);
fledasty_queue_push(&test_queue, &test); printf("Queue peeked: %d\n", fledasty_queue_int_peek(&test_queue));
int *peeked_queue_data = (int*)fledasty_queue_peek(&test_queue);
printf("Queue peeked: %d\n", *peeked_queue_data);
for (int i = test_queue.size; i > 0; i -= 1) { for (int i = test_queue.size; i > 0; i -= 1) {
int *popped_data = (int*)fledasty_queue_pop(&test_queue); printf("Queue popped: %d\n", fledasty_queue_int_pop(&test_queue));
printf("Queue popped: %d\n", *popped_data);
} }
fledasty_queue_clear(&test_queue); fledasty_queue_int_clear(&test_queue);
if (fledasty_queue_is_empty(&test_queue)) { if (fledasty_queue_int_is_empty(&test_queue)) {
printf("Queue is empty\n"); printf("Queue is empty\n");
} }
fledasty_queue_destroy(&test_queue); fledasty_queue_int_free(&test_queue);
FledastyStack test_stack;
fledasty_stack_initialize(&test_stack, (int[]){ 11, 12, 13, 14, 15 }, 5, sizeof(int));
FledastyStack_int test_stack = { 0, 0, NULL };
for (int i = 0; i < 10; i += 1) { for (int i = 0; i < 10; i += 1) {
fledasty_stack_push(&test_stack, &i); fledasty_stack_int_push(&test_stack, i);
} }
fledasty_stack_shrink_to_fit(&test_stack); fledasty_stack_int_shrink_to_fit(&test_stack);
printf("Stack schrinked to fit %s\n", (test_stack.capacity == test_stack.size) ? "succeeded" : "failed"); printf("Stack schrinked to fit %s\n", (test_stack.capacity == test_stack.size) ? "succeeded" : "failed");
printf("Stack peeked: %d\n", fledasty_stack_int_peek(&test_stack));
int *peeked_stack_data = (int*)fledasty_stack_peek(&test_stack);
printf("Stack peeked: %d\n", *peeked_stack_data);
for (int i = test_stack.size; i > 0; i -= 1) { for (int i = test_stack.size; i > 0; i -= 1) {
int *popped_data = (int*)fledasty_stack_pop(&test_stack); printf("Stack popped: %d\n", fledasty_stack_int_pop(&test_stack));
printf("Stack popped: %d\n", *popped_data);
} }
fledasty_stack_clear(&test_stack); fledasty_stack_int_clear(&test_stack);
if (fledasty_stack_is_empty(&test_stack)) { if (fledasty_stack_int_is_empty(&test_stack)) {
printf("Stack is empty\n"); printf("Stack is empty\n");
} }
fledasty_stack_destroy(&test_stack); fledasty_stack_int_free(&test_stack);
FledastyDynamicArray test_dynamic_array; FledastyDynamicArray test_dynamic_array;
fledasty_dynamic_array_initialize(&test_dynamic_array, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int)); fledasty_dynamic_array_initialize(&test_dynamic_array, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));