TwiceAsNice  2019-02-18
Classes | Functions | Variables
fq.c File Reference

a fifo queue that never fills. More...

#include "fq.h"
#include <stdlib.h>
#include <string.h>
Include dependency graph for fq.c:

Classes

struct  _FQ
 

Functions

static void chkFQ (FQ *q)
 
FQnewFQ (int grow)
 
void delFQ (FQ *q)
 
void pushFQ (FQ *q, void *e)
 
void * popFQ (FQ *q)
 
void * peekFQ (FQ *q)
 
void * peekiFQ (FQ *q, int i)
 
int nFQ (FQ *q)
 
void setMemFuncsFQ (void *(*newmalloc)(size_t size), void *(*newrealloc)(void *ptr, size_t size), void(*newfree)(void *ptr))
 

Variables

static void *(* fqmalloc )(size_t size) = malloc
 
static void *(* fqrealloc )(void *ptr, size_t size) = realloc
 
static void(* fqfree )(void *ptr) = free
 

Detailed Description

a fifo queue that never fills.

Generic FIFO Queue.

an FQ is a FIFO list of pointers to void, each called an "element". elements are added at q[head]. there are (nq) elements in the list. the element to be removed next is q[head-nq]. there are (head-nq) empty slots at the front of the q array. there are (nmem-head) elements available at the end. if the head reaches the end, existing enties are slid to the front of the array and total memory is adjusted up or down as required.

example:

<-----------------— nmem = 17 ------------------------------—>

<– head - nq = 6 —> <– nq = 4 –> <-— nmem - head = 7 –>

| | | | | | | x | x | x | x | | | | | | | |

0 1 2 3 4 5 6 7 8 9 ^ head = 10

Author
Elwood Downey

Function Documentation

◆ chkFQ()

static void chkFQ ( FQ q)
static

◆ delFQ()

void delFQ ( FQ q)

◆ newFQ()

FQ* newFQ ( int  grow)

◆ nFQ()

int nFQ ( FQ q)

◆ peekFQ()

void* peekFQ ( FQ q)

◆ peekiFQ()

void* peekiFQ ( FQ q,
int  i 
)

◆ popFQ()

void* popFQ ( FQ q)

◆ pushFQ()

void pushFQ ( FQ q,
void *  e 
)

◆ setMemFuncsFQ()

void setMemFuncsFQ ( void *(*)(size_t size)  newmalloc,
void *(*)(void *ptr, size_t size)  newrealloc,
void(*)(void *ptr)  newfree 
)

Variable Documentation

◆ fqfree

void(* fqfree) (void *ptr) = free
static

◆ fqmalloc

void*(* fqmalloc) (size_t size) = malloc
static

◆ fqrealloc

void*(* fqrealloc) (void *ptr, size_t size) = realloc
static