merged with herbglitch/master
This commit is contained in:
commit
c822075173
8 changed files with 303 additions and 5 deletions
|
|
@ -38,6 +38,7 @@ set(ARCHEUS_STD_SOURCES
|
|||
src/std/handler.c
|
||||
src/std/hashtable.c
|
||||
src/std/io.c
|
||||
src/std/stack.c
|
||||
src/std/string.c
|
||||
src/std/vector.c
|
||||
src/std/defaults/config.c
|
||||
|
|
|
|||
18
include/arc/std/bool.h
Normal file
18
include/arc/std/bool.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef ARC_STD_BOOL_H_
|
||||
#define ARC_STD_BOOL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define ARC_Bool bool
|
||||
#define ARC_True true
|
||||
#define ARC_False false
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ARC_STD_BOOL_H_
|
||||
57
include/arc/std/queue.h
Normal file
57
include/arc/std/queue.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef ARC_STD_QUEUE_H_
|
||||
#define ARC_STD_QUEUE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief a queue type
|
||||
*/
|
||||
typedef struct ARC_Queue ARC_Queue;
|
||||
|
||||
/**
|
||||
* @brief creates ARC_Queue type
|
||||
*
|
||||
* @param queue ARC_Queue to initialize
|
||||
*/
|
||||
void ARC_Queue_Create(ARC_Queue **queue);
|
||||
|
||||
/**
|
||||
* @brief destroyes ARC_Queue type
|
||||
*/
|
||||
void ARC_Queue_Destroy(ARC_Queue *queue);
|
||||
|
||||
/**
|
||||
* @brief pushes value to end of queue
|
||||
*
|
||||
* @param queue ARC_Queue to push to
|
||||
* @param data data that is being pushed
|
||||
*/
|
||||
void ARC_Queue_Push(ARC_Queue *queue, void *data);
|
||||
|
||||
/**
|
||||
* @brief pops the front off of the ARC_Queue
|
||||
*
|
||||
* @param queue ARC_Queue to remove from
|
||||
*
|
||||
* @return the poped data from the queue as a void *
|
||||
*/
|
||||
void *ARC_Queue_Pop(ARC_Queue *queue);
|
||||
|
||||
/**
|
||||
* @brief gets size of queue
|
||||
*
|
||||
* @param vector ARC_Queue to get size from
|
||||
*
|
||||
* @return the queues size
|
||||
*/
|
||||
uint32_t ARC_Queue_Size(ARC_Queue *queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ARC_STD_QUEUE_H_
|
||||
57
include/arc/std/stack.h
Normal file
57
include/arc/std/stack.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef ARC_STD_STACK_H_
|
||||
#define ARC_STD_STACK_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief a stack type
|
||||
*/
|
||||
typedef struct ARC_Stack ARC_Stack;
|
||||
|
||||
/**
|
||||
* @brief creates ARC_Stack type
|
||||
*
|
||||
* @param stack ARC_Stack to initialize
|
||||
*/
|
||||
void ARC_Stack_Create(ARC_Stack **stack);
|
||||
|
||||
/**
|
||||
* @brief destroyes ARC_Stack type
|
||||
*/
|
||||
void ARC_Stack_Destroy(ARC_Stack *stack);
|
||||
|
||||
/**
|
||||
* @brief pushes value on stack
|
||||
*
|
||||
* @param stack ARC_Stack to push to
|
||||
* @param data data that is being pushed
|
||||
*/
|
||||
void ARC_Stack_Push(ARC_Stack *stack, void *data);
|
||||
|
||||
/**
|
||||
* @brief pops top off of ARC_Stack
|
||||
*
|
||||
* @param stack ARC_Stack to remove from
|
||||
*
|
||||
* @return the poped data from the stack as a void *
|
||||
*/
|
||||
void *ARC_Stack_Pop(ARC_Stack *stack);
|
||||
|
||||
/**
|
||||
* @brief gets size of stack
|
||||
*
|
||||
* @param stack ARC_Stack to get size from
|
||||
*
|
||||
* @return the stacks size
|
||||
*/
|
||||
uint32_t ARC_Stack_Size(ARC_Stack *stack);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ARC_STD_STACK_H_
|
||||
|
|
@ -18,7 +18,7 @@ typedef struct ARC_Vector ARC_Vector;
|
|||
* @param a first data struct
|
||||
* @param b second data struct
|
||||
*
|
||||
* @return 0 when a == b
|
||||
* @return 0 when a == b, TODO: return and ARC_Bool
|
||||
*/
|
||||
typedef int32_t (* ARC_Vector_CompareDataFn)(void *a, void *b);
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ void ARC_Vector_Add(ARC_Vector *vector, void *data);
|
|||
*
|
||||
* @param vector ARC_Vector to remove from
|
||||
* @param data data that is being removed
|
||||
* @param compare comparison callback to get check if data should be removed
|
||||
*/
|
||||
void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn compare);
|
||||
|
||||
|
|
@ -62,6 +63,8 @@ void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index);
|
|||
* @brief gets size of vector
|
||||
*
|
||||
* @param vector ARC_Vector to get size from
|
||||
*
|
||||
* @return the pointer of the vectors size, TODO: don't pass as a pointer
|
||||
*/
|
||||
uint32_t *ARC_Vector_Size(ARC_Vector *vector);
|
||||
|
||||
|
|
|
|||
86
src/std/queue.c
Normal file
86
src/std/queue.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#include "arc/std/queue.h"
|
||||
|
||||
#include "arc/std/errno.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct ARC_QueueNode ARC_QueueNode;
|
||||
|
||||
struct ARC_QueueNode {
|
||||
ARC_QueueNode *next;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct ARC_Queue {
|
||||
uint32_t currentSize;
|
||||
ARC_QueueNode *node;
|
||||
};
|
||||
|
||||
void ARC_Queue_Create(ARC_Queue **queue){
|
||||
*queue = (ARC_Queue *)malloc(sizeof(ARC_Queue));
|
||||
(*queue)->currentSize = 0;
|
||||
(*queue)->node = NULL;
|
||||
}
|
||||
|
||||
void ARC_Queue_Destroy(ARC_Queue *queue){
|
||||
if(queue->currentSize != 0 || queue->node != NULL){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_ERR("ARC_Queue_Destroy(queue) called, but queue was not empty");
|
||||
return;
|
||||
}
|
||||
|
||||
free(queue);
|
||||
}
|
||||
|
||||
void ARC_Queue_Push(ARC_Queue *queue, void *data){
|
||||
if(queue->currentSize == ~(uint32_t)0){
|
||||
arc_errno = ARC_ERRNO_OVERFLOW;
|
||||
ARC_DEBUG_ERR("ARC_Queue_Push(queue) called, size of queue is maxed, cannot add another node");
|
||||
return;
|
||||
}
|
||||
|
||||
ARC_QueueNode *end = queue->node;
|
||||
for(uint32_t i = 0; i < queue->currentSize; i++){
|
||||
if(end == NULL){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
ARC_DEBUG_ERR("ARC_Queue_Push(queue), when getting end node encountered a NULL node");
|
||||
return;
|
||||
}
|
||||
|
||||
end = end->next;
|
||||
}
|
||||
|
||||
ARC_QueueNode *node = (ARC_QueueNode *)malloc(sizeof(ARC_QueueNode));
|
||||
node->data = data;
|
||||
node->next = NULL;
|
||||
|
||||
end->next = node;
|
||||
|
||||
queue->currentSize++;
|
||||
}
|
||||
|
||||
void *ARC_Queue_Pop(ARC_Queue *queue){
|
||||
if(queue->currentSize == 0){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but queue was not empty");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ARC_QueueNode *node = queue->node;
|
||||
if(node == NULL){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but node was NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
queue->node = node->next;
|
||||
void *nodeData = node->data;
|
||||
free(node);
|
||||
|
||||
queue->currentSize--;
|
||||
|
||||
return nodeData;
|
||||
}
|
||||
|
||||
uint32_t ARC_Queue_Size(ARC_Queue *queue){
|
||||
return queue->currentSize;
|
||||
}
|
||||
76
src/std/stack.c
Normal file
76
src/std/stack.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#include "arc/std/stack.h"
|
||||
|
||||
#include "arc/std/errno.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct ARC_StackNode ARC_StackNode;
|
||||
|
||||
struct ARC_StackNode {
|
||||
ARC_StackNode *next;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct ARC_Stack {
|
||||
uint32_t currentSize;
|
||||
ARC_StackNode *node;
|
||||
};
|
||||
|
||||
void ARC_Stack_Create(ARC_Stack **stack){
|
||||
*stack = (ARC_Stack *)malloc(sizeof(ARC_Stack));
|
||||
(*stack)->currentSize = 0;
|
||||
(*stack)->node = NULL;
|
||||
}
|
||||
|
||||
void ARC_Stack_Destroy(ARC_Stack *stack){
|
||||
if(stack->currentSize != 0 || stack->node != NULL){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_ERR("ARC_Stack_Destroy(stack) called, but stack was not empty");
|
||||
return;
|
||||
}
|
||||
|
||||
free(stack);
|
||||
}
|
||||
|
||||
void ARC_Stack_Push(ARC_Stack *stack, void *data){
|
||||
if(stack->currentSize == ~(uint32_t)0){
|
||||
arc_errno = ARC_ERRNO_OVERFLOW;
|
||||
ARC_DEBUG_ERR("ARC_Stack_Push(stack) called, size of stack is maxed, cannot add another node");
|
||||
return;
|
||||
}
|
||||
|
||||
ARC_StackNode *node = (ARC_StackNode *)malloc(sizeof(ARC_StackNode));
|
||||
node->data = data;
|
||||
node->next = NULL;
|
||||
|
||||
node->next = stack->node;
|
||||
stack->node = node;
|
||||
|
||||
stack->currentSize++;
|
||||
}
|
||||
|
||||
void *ARC_Stack_Pop(ARC_Stack *stack){
|
||||
if(stack->currentSize == 0){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_ERR("ARC_Stack_Pop(stack) called, but stack was not empty");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ARC_StackNode *node = stack->node;
|
||||
if(node == NULL){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
ARC_DEBUG_ERR("ARC_Stack_Pop(stack) called, but node was NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stack->node = node->next;
|
||||
void *nodeData = node->data;
|
||||
free(node);
|
||||
|
||||
stack->currentSize--;
|
||||
|
||||
return nodeData;
|
||||
}
|
||||
|
||||
uint32_t ARC_Stack_Size(ARC_Stack *stack){
|
||||
return stack->currentSize;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue