Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
queue.h File Reference

generic first-in-first-out buffer (queue) More...

#include <assert.h>
#include <cgraph/alloc.h>
#include <stddef.h>
#include <string.h>
Include dependency graph for queue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  queue_t
 

Functions

static queue_t queue_new (size_t hint)
 
static void queue_push (queue_t *q, void *item)
 
static void * queue_pop (queue_t *q)
 
static void queue_free (queue_t *q)
 

Detailed Description

The header-only implementation below defines a queue with an optional initial capacity that expands on-demand if necessary. Expansions always succeed or exit on out-of-memory. A queue item is a generic pointer, void *.

Definition in file queue.h.

Function Documentation

◆ queue_free()

static void queue_free ( queue_t q)
inlinestatic

deallocate backing memory and re-initialize a queue

Parameters
qQueue to operate on

Definition at line 108 of file queue.h.

References queue_t::base, free(), and NULL.

Referenced by build_ranks(), init_rank(), setNStepsToCenter(), and travBFS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_new()

static queue_t queue_new ( size_t  hint)
inlinestatic

create a new queue

The hint should be a guess of the intended occupancy ceiling. If the guess is inaccurate, the queue expands on-demand anyway, so there are few consequences for getting it wrong. It is possible to pass 0 as the hint, but in this case you are better of using zero initialization for brevity.

Parameters
hintNumber of initial slots to allocate
Returns
An empty queue

Definition at line 39 of file queue.h.

References queue_t::base, and gv_calloc().

Referenced by init_rank().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_pop()

static void * queue_pop ( queue_t q)
inlinestatic

remove an item from the head of a queue

Parameters
qQueue to operate on
Returns
The popped entry on success or NULL if the queue was empty

Definition at line 90 of file queue.h.

References queue_t::base, queue_t::capacity, queue_t::head, NULL, and queue_t::size.

Referenced by build_ranks(), init_rank(), setNStepsToCenter(), and travBFS().

Here is the caller graph for this function:

◆ queue_push()

static void queue_push ( queue_t q,
void *  item 
)
inlinestatic

insert a new item at the tail of a queue

It is possible to push NULL entries. But then you will be unable to distinguish popping this entry from the queue being empty.

Parameters
qQueue to operate on
itemEntry to insert

Definition at line 52 of file queue.h.

References queue_t::base, queue_t::capacity, gv_recalloc(), queue_t::head, NULL, prefix, and queue_t::size.

Referenced by build_ranks(), enqueue_neighbors(), init_rank(), setNStepsToCenter(), and travBFS().

Here is the call graph for this function:
Here is the caller graph for this function: