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

Go to the source code of this file.

## Data Structures

struct | ARC_QueueNode
struct | ARC_Queue

## Typedefs

typedef struct ARC_QueueNode | ARC_QueueNode

## Functions

void | ARC_Queue_Create (ARC_Queue **queue)
| creates ARC_Queue type
void | ARC_Queue_Destroy (ARC_Queue *queue)
| destroyes ARC_Queue type
void | ARC_Queue_Push (ARC_Queue *queue, void *data)
| pushes value to end of queue
void * | ARC_Queue_Pop (ARC_Queue *queue)
| pops the front off of the ARC_Queue
uint32_t | ARC_Queue_Size (ARC_Queue *queue)
| gets size of queue

## Typedef Documentation

## ARC_QueueNode

typedef struct ARC_QueueNode ARC_QueueNode

Definition at line 6 of file queue.c.

## Function Documentation

## ARC_Queue_Create()

void ARC_Queue_Create | ( | ARC_Queue ** | queue | ) |

creates ARC_Queue type

Parameters

  queue | ARC_Queue to initialize

Definition at line 18 of file queue.c.

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

References ARC_Queue::currentSize.

## ARC_Queue_Destroy()

void ARC_Queue_Destroy | ( | ARC_Queue * | queue | ) |

destroyes ARC_Queue type

Definition at line 24 of file queue.c.

{
if(queue->currentSize != 0 || queue->node != NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_Queue_Destroy(queue) called, but queue was not empty");
return;
}
free(queue);
}
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_Queue::node
ARC_QueueNode * node
Definition queue.c:15

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

## ARC_Queue_Pop()

void * ARC_Queue_Pop | ( | ARC_Queue * | queue | ) |

pops the front off of the ARC_Queue

Parameters

  queue | ARC_Queue to remove from

Returns
  the poped data from the queue as a void *

Definition at line 72 of file queue.c.

{
if(queue->currentSize == 0){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_Queue_Pop(queue) called, but queue was empty");
return NULL;
}
ARC_QueueNode *node = queue->node;
if(node == NULL){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG_ERROR("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;
}
ARC_ERRNO_NULL
#define ARC_ERRNO_NULL
Definition errno.h:6
ARC_QueueNode
Definition queue.c:8
ARC_QueueNode::next
ARC_QueueNode * next
Definition queue.c:9
ARC_QueueNode::data
void * data
Definition queue.c:10

References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_ERRNO_DATA, ARC_ERRNO_NULL, ARC_Queue::currentSize, ARC_QueueNode::data, ARC_QueueNode::next, and ARC_Queue::node.

## ARC_Queue_Push()

void ARC_Queue_Push | ( | ARC_Queue * | queue,
|  | void * | data )

pushes value to end of queue

Parameters

  queue | ARC_Queue to push to
  data | data that is being pushed

Definition at line 34 of file queue.c.

{
if(queue->currentSize == ~(uint32_t)0){
arc_errno = ARC_ERRNO_OVERFLOW;
ARC_DEBUG_LOG_ERROR("ARC_Queue_Push(queue) called, size of queue is maxed, cannot add another node");
return;
}
if(queue->currentSize == 0){
ARC_QueueNode *node = (ARC_QueueNode *)malloc(sizeof(ARC_QueueNode));
node->data = data;
node->next = NULL;
queue->node = node;
queue->currentSize++;
return;
}
ARC_QueueNode *end = queue->node;
for(uint32_t i = 1; i < queue->currentSize; i++){
if(end->next == NULL){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG_ERROR("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++;
}
ARC_ERRNO_OVERFLOW
#define ARC_ERRNO_OVERFLOW
Definition errno.h:10

References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_ERRNO_NULL, ARC_ERRNO_OVERFLOW, ARC_Queue::currentSize, ARC_QueueNode::data, ARC_QueueNode::next, and ARC_Queue::node.

## ARC_Queue_Size()

uint32_t ARC_Queue_Size | ( | ARC_Queue * | queue | ) |

gets size of queue

Parameters

  vector | ARC_Queue to get size from

Returns
  the queues size

Definition at line 95 of file queue.c.

{
return queue->currentSize;
}

References ARC_Queue::currentSize.