reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
pqueue_base.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, Volkan Yazıcı <volkan.yazici@gmail.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * Modified by Marten Lohstroh (May, 2019).
26 * Changes:
27 * - Require implementation of a pqueue_eq_elem_f function to determine
28 * whether two elements are equal or not; and
29 * - The provided pqueue_eq_elem_f implementation is used to test and
30 * search for equal elements present in the queue; and
31 * - Removed capability to reassign priorities.
32 *
33 * Modified by Byeonggil Jun (Apr, 2024).
34 * Changes:
35 * - Made the pqueue_cmp_pri_f function return do the three-way comparison
36 * rather than the two-way comparison.
37 * - The changed pqueue_cmp_pri_f function is used to check the equality of
38 * two elements in the pqueue_find_equal_same_priority function.
39 * - Remove the pqueue_find_equal function.
40 *
41 * @brief Priority Queue function declarations used as a base for Lingua Franca priority queues.
42 *
43 * @{
44 */
45
46#ifndef PQUEUE_BASE_H
47#define PQUEUE_BASE_H
48
49#include <stddef.h>
50
52typedef unsigned long long pqueue_pri_t;
53
55typedef pqueue_pri_t (*pqueue_get_pri_f)(void* a);
56
58typedef int (*pqueue_cmp_pri_f)(pqueue_pri_t next, pqueue_pri_t curr);
59
61typedef int (*pqueue_eq_elem_f)(void* next, void* curr);
62
64typedef size_t (*pqueue_get_pos_f)(void* a);
65
67typedef void (*pqueue_set_pos_f)(void* a, size_t pos);
68
70typedef void (*pqueue_print_entry_f)(void* a);
71
85
104
109void pqueue_free(pqueue_t* q);
110
115size_t pqueue_size(pqueue_t* q);
116
123int pqueue_insert(pqueue_t* q, void* d);
124
130void* pqueue_pop(pqueue_t* q);
131
140void pqueue_empty_into(pqueue_t** dest, pqueue_t** src);
141
148void* pqueue_find_same_priority(pqueue_t* q, void* e);
149
158
165int pqueue_remove(pqueue_t* q, void* e);
166
172void* pqueue_peek(pqueue_t* q);
173
180
189
197
198#endif /* PQUEUE_BASE_H */
struct pqueue_t pqueue_t
void pqueue_print(pqueue_t *q, pqueue_print_entry_f print)
Definition pqueue_base.c:300
int(* pqueue_cmp_pri_f)(pqueue_pri_t next, pqueue_pri_t curr)
Definition pqueue_base.h:58
void * pqueue_find_same_priority(pqueue_t *q, void *e)
Definition pqueue_base.c:207
size_t(* pqueue_get_pos_f)(void *a)
Definition pqueue_base.h:64
pqueue_t * pqueue_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.
Definition pqueue_base.c:128
int(* pqueue_eq_elem_f)(void *next, void *curr)
Definition pqueue_base.h:61
void * pqueue_pop(pqueue_t *q)
Definition pqueue_base.c:248
void(* pqueue_print_entry_f)(void *a)
Definition pqueue_base.h:70
int pqueue_remove(pqueue_t *q, void *e)
Definition pqueue_base.c:235
void * pqueue_find_equal_same_priority(pqueue_t *q, void *e)
Definition pqueue_base.c:209
void * pqueue_peek(pqueue_t *q)
Definition pqueue_base.c:282
void pqueue_empty_into(pqueue_t **dest, pqueue_t **src)
Empty 'src' into 'dest'.
Definition pqueue_base.c:261
pqueue_pri_t(* pqueue_get_pri_f)(void *a)
Definition pqueue_base.h:55
void pqueue_free(pqueue_t *q)
Definition pqueue_base.c:152
unsigned long long pqueue_pri_t
Definition pqueue_base.h:52
void pqueue_dump(pqueue_t *q, pqueue_print_entry_f print)
Definition pqueue_base.c:290
int pqueue_insert(pqueue_t *q, void *d)
Definition pqueue_base.c:211
size_t pqueue_size(pqueue_t *q)
Definition pqueue_base.c:157
int pqueue_is_valid(pqueue_t *q)
Definition pqueue_base.c:353
void(* pqueue_set_pos_f)(void *a, size_t pos)
Definition pqueue_base.h:67
Definition pqueue_base.h:73
pqueue_set_pos_f setpos
Definition pqueue_base.h:80
pqueue_get_pos_f getpos
Definition pqueue_base.h:79
pqueue_eq_elem_f eqelem
Definition pqueue_base.h:81
size_t avail
Definition pqueue_base.h:75
size_t size
Definition pqueue_base.h:74
void ** d
Definition pqueue_base.h:83
size_t step
Definition pqueue_base.h:76
pqueue_get_pri_f getpri
Definition pqueue_base.h:78
pqueue_print_entry_f prt
Definition pqueue_base.h:82
pqueue_cmp_pri_f cmppri
Definition pqueue_base.h:77