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 * @brief Priority Queue function declarations used as a base for Lingua Franca priority queues.
34 *
35 * @{
36 */
37
38
39#ifndef PQUEUE_BASE_H
40#define PQUEUE_BASE_H
41
42#include <stddef.h>
43
45typedef unsigned long long pqueue_pri_t;
46
49
52
54typedef int (*pqueue_eq_elem_f)(void* next, void* curr);
55
57typedef size_t (*pqueue_get_pos_f)(void *a);
58
60typedef void (*pqueue_set_pos_f)(void *a, size_t pos);
61
63typedef void (*pqueue_print_entry_f)(void *a);
64
79
97pqueue_init(size_t n,
98 pqueue_cmp_pri_f cmppri,
99 pqueue_get_pri_f getpri,
100 pqueue_get_pos_f getpos,
101 pqueue_set_pos_f setpos,
102 pqueue_eq_elem_f eqelem,
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
131void
134 void *d);
135
141void *pqueue_pop(pqueue_t *q);
142
152
161
171
178int pqueue_remove(pqueue_t *q, void *e);
179
185void *pqueue_peek(pqueue_t *q);
186
187
194
202void
205
213
214#endif /* PQUEUE_BASE_H */
return address
Definition hashmap.h:74
struct pqueue_t pqueue_t
void pqueue_print(pqueue_t *q, pqueue_print_entry_f print)
Definition pqueue_base.c:304
int(* pqueue_cmp_pri_f)(pqueue_pri_t next, pqueue_pri_t curr)
Definition pqueue_base.h:51
void * pqueue_find_equal(pqueue_t *q, void *e, pqueue_pri_t max_priority)
Definition pqueue_base.c:210
size_t(* pqueue_get_pos_f)(void *a)
Definition pqueue_base.h:57
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:118
int(* pqueue_eq_elem_f)(void *next, void *curr)
Definition pqueue_base.h:54
void * pqueue_pop(pqueue_t *q)
Definition pqueue_base.c:249
void pqueue_change_priority(pqueue_t *q, pqueue_pri_t new_pri, void *d)
void(* pqueue_print_entry_f)(void *a)
Definition pqueue_base.h:63
int pqueue_remove(pqueue_t *q, void *e)
Definition pqueue_base.c:237
void * pqueue_find_equal_same_priority(pqueue_t *q, void *e)
Definition pqueue_base.c:206
void * pqueue_peek(pqueue_t *q)
Definition pqueue_base.c:283
void pqueue_empty_into(pqueue_t **dest, pqueue_t **src)
Empty 'src' into 'dest'.
Definition pqueue_base.c:262
pqueue_pri_t(* pqueue_get_pri_f)(void *a)
Definition pqueue_base.h:48
void pqueue_free(pqueue_t *q)
Definition pqueue_base.c:147
unsigned long long pqueue_pri_t
Definition pqueue_base.h:45
void pqueue_dump(pqueue_t *q, pqueue_print_entry_f print)
Definition pqueue_base.c:291
int pqueue_insert(pqueue_t *q, void *d)
Definition pqueue_base.c:214
size_t pqueue_size(pqueue_t *q)
Definition pqueue_base.c:152
int pqueue_is_valid(pqueue_t *q)
Definition pqueue_base.c:359
void(* pqueue_set_pos_f)(void *a, size_t pos)
Definition pqueue_base.h:60
Definition pqueue_base.h:67
pqueue_set_pos_f setpos
Definition pqueue_base.h:74
pqueue_get_pos_f getpos
Definition pqueue_base.h:73
pqueue_eq_elem_f eqelem
Definition pqueue_base.h:75
size_t avail
Definition pqueue_base.h:69
size_t size
Definition pqueue_base.h:68
void ** d
Definition pqueue_base.h:77
size_t step
Definition pqueue_base.h:70
pqueue_get_pri_f getpri
Definition pqueue_base.h:72
pqueue_print_entry_f prt
Definition pqueue_base.h:76
pqueue_cmp_pri_f cmppri
Definition pqueue_base.h:71