Loading...
Searching...
No Matches
stack.c File Reference
`#include "arc/std/stack.h"`
`#include "arc/std/errno.h"`
`#include <stdlib.h>`

Go to the source code of this file.

## Data Structures

struct | ARC_StackNode
struct | ARC_Stack

## Typedefs

typedef struct ARC_StackNode | ARC_StackNode

## Functions

void | ARC_Stack_Create (ARC_Stack **stack)
| creates ARC_Stack type
void | ARC_Stack_Destroy (ARC_Stack *stack)
| destroyes ARC_Stack type
void | ARC_Stack_Push (ARC_Stack *stack, void *data)
| pushes value on stack
void * | ARC_Stack_Pop (ARC_Stack *stack)
| pops top off of ARC_Stack
uint32_t | ARC_Stack_Size (ARC_Stack *stack)
| gets size of stack

## Typedef Documentation

## ARC_StackNode

typedef struct ARC_StackNode ARC_StackNode

Definition at line 6 of file stack.c.

## Function Documentation

## ARC_Stack_Create()

void ARC_Stack_Create | ( | ARC_Stack ** | stack | ) |

creates ARC_Stack type

Parameters

  stack | ARC_Stack to initialize

Definition at line 18 of file stack.c.

{
*stack = (ARC_Stack *)malloc(sizeof(ARC_Stack));
(*stack)->currentSize = 0;
(*stack)->node = NULL;
}
ARC_Stack
Definition stack.c:13
ARC_Stack::currentSize
uint32_t currentSize
Definition stack.c:14

References ARC_Stack::currentSize.

## ARC_Stack_Destroy()

void ARC_Stack_Destroy | ( | ARC_Stack * | stack | ) |

destroyes ARC_Stack type

Definition at line 24 of file stack.c.

{
if(stack->currentSize != 0 || stack->node != NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_Stack_Destroy(stack) called, but stack was not empty");
return;
}
free(stack);
}
arc_errno
int32_t arc_errno
Definition errno.c:5
ARC_DEBUG_LOG_ERROR
#define ARC_DEBUG_LOG_ERROR(STR)
Definition errno.h:39
ARC_ERRNO_DATA
#define ARC_ERRNO_DATA
Definition errno.h:7
ARC_Stack::node
ARC_StackNode * node
Definition stack.c:15

References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_ERRNO_DATA, ARC_Stack::currentSize, and ARC_Stack::node.

## ARC_Stack_Pop()

void * ARC_Stack_Pop | ( | ARC_Stack * | stack | ) |

pops top off of ARC_Stack

Parameters

  stack | ARC_Stack to remove from

Returns
  the poped data from the stack as a void *

Definition at line 51 of file stack.c.

{
if(stack->currentSize == 0){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("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_LOG_ERROR("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;
}
ARC_ERRNO_NULL
#define ARC_ERRNO_NULL
Definition errno.h:6
ARC_StackNode
Definition stack.c:8
ARC_StackNode::next
ARC_StackNode * next
Definition stack.c:9
ARC_StackNode::data
void * data
Definition stack.c:10

References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_ERRNO_DATA, ARC_ERRNO_NULL, ARC_Stack::currentSize, ARC_StackNode::data, ARC_StackNode::next, and ARC_Stack::node.

## ARC_Stack_Push()

void ARC_Stack_Push | ( | ARC_Stack * | stack,
|  | void * | data )

pushes value on stack

Parameters

  stack | ARC_Stack to push to
  data | data that is being pushed

Definition at line 34 of file stack.c.

{
if(stack->currentSize == ~(uint32_t)0){
arc_errno = ARC_ERRNO_OVERFLOW;
ARC_DEBUG_LOG_ERROR("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++;
}
ARC_ERRNO_OVERFLOW
#define ARC_ERRNO_OVERFLOW
Definition errno.h:10

References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_ERRNO_OVERFLOW, ARC_Stack::currentSize, ARC_StackNode::data, ARC_StackNode::next, and ARC_Stack::node.

## ARC_Stack_Size()

uint32_t ARC_Stack_Size | ( | ARC_Stack * | stack | ) |

gets size of stack

Parameters

  stack | ARC_Stack to get size from

Returns
  the stacks size

Definition at line 74 of file stack.c.

{
return stack->currentSize;
}

References ARC_Stack::currentSize.