reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
pqueue_base.h File Reference

Priority Queue function declarations used as a base for Lingua Franca priority queues. More...

#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  pqueue_t
 The priority queue struct. More...

Typedefs

typedef int(* pqueue_cmp_pri_f) (pqueue_pri_t next, pqueue_pri_t curr)
 Callback to compare two priorities.
typedef int(* pqueue_eq_elem_f) (void *next, void *curr)
 Callback to determine whether two elements are equivalent.
typedef size_t(* pqueue_get_pos_f) (void *a)
 Callback functions to get the position of an element.
typedef pqueue_pri_t(* pqueue_get_pri_f) (void *a)
 Callback to get the priority of an element.
typedef unsigned long long pqueue_pri_t
 Priority data type.
typedef void(* pqueue_print_entry_f) (void *a)
 Debug callback function to print a entry.
typedef void(* pqueue_set_pos_f) (void *a, size_t pos)
 Callback functions to set the position of an element.
typedef struct pqueue_t pqueue_t
 The priority queue struct.

Functions

void pqueue_dump (pqueue_t *q, pqueue_print_entry_f print)
 Dump the queue and it's internal structure.
void pqueue_empty_into (pqueue_t **dest, pqueue_t **src)
 Empty 'src' into 'dest'.
void * pqueue_find_equal_same_priority (pqueue_t *q, void *e)
 Return an entry with the same priority (determined by cmppri) that matches the supplied entry (determined by eqelem) or NULL if there is no such entry.
void * pqueue_find_same_priority (pqueue_t *q, void *e)
 Return an entry with the same priority as the specified entry or NULL if there is no such entry.
void pqueue_free (pqueue_t *q)
 Free all memory used by the queue.
pqueue_tpqueue_init (size_t n, pqueue_cmp_pri_f cmppri, pqueue_get_pri_f getpri, pqueue_get_pos_f getpos, pqueue_set_pos_f setpos, pqueue_eq_elem_f eqelem, pqueue_print_entry_f prt)
 Allocate and initialize a priority queue.
int pqueue_insert (pqueue_t *q, void *d)
 Insert an element into the queue.
int pqueue_is_valid (pqueue_t *q)
 Check that the all entries are in the right order, etc.
void * pqueue_peek (pqueue_t *q)
 Access highest-ranking item without removing it.
void * pqueue_pop (pqueue_t *q)
 Pop the highest-ranking item from the queue.
void pqueue_print (pqueue_t *q, pqueue_print_entry_f print)
 Print the contents of the queue.
int pqueue_remove (pqueue_t *q, void *e)
 Remove an item from the queue.
size_t pqueue_size (pqueue_t *q)
 Return the size of the queue.

Detailed Description

Priority Queue function declarations used as a base for Lingua Franca priority queues.

Author
Volkan Yazıcı volkan.yazici@gmail.com
Marten Lohstroh
Byeonggil Jun

License

Copyright (c) 2014, Volkan Yazıcı volkan.yazici@gmail.com

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Modified by Marten Lohstroh (May, 2019). Changes:

  • Require implementation of a pqueue_eq_elem_f function to determine whether two elements are equal or not; and
  • The provided pqueue_eq_elem_f implementation is used to test and search for equal elements present in the queue; and
  • Removed capability to reassign priorities.

Modified by Byeonggil Jun (Apr, 2024). Changes:

  • Made the pqueue_cmp_pri_f function return do the three-way comparison rather than the two-way comparison.
  • The changed pqueue_cmp_pri_f function is used to check the equality of two elements in the pqueue_find_equal_same_priority function.
  • Remove the pqueue_find_equal function.

Function Documentation

◆ pqueue_dump()

void pqueue_dump ( pqueue_t * q,
pqueue_print_entry_f print )

Dump the queue and it's internal structure.

Parameters
qThe queue
printThe callback function to print the entry

◆ pqueue_is_valid()

int pqueue_is_valid ( pqueue_t * q)

Check that the all entries are in the right order, etc.

Parameters
qThe queue