-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpq_utils.c
More file actions
44 lines (38 loc) · 1.44 KB
/
Copy pathpq_utils.c
File metadata and controls
44 lines (38 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pq_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dporhomo <dporhomo@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/06 12:13:37 by dporhomo #+# #+# */
/* Updated: 2026/06/15 14:42:05 by dporhomo ### ########.fr */
/* */
/* ************************************************************************** */
/*Performs pq compare, swap and free*/
#include "codexion.h"
void pq_free(t_pqueue *pq)
{
if (pq && pq->heap)
{
free(pq->heap);
pq->heap = NULL;
}
}
void pq_swap(t_pqueue *pq, int i, int j)
{
t_request tmp;
tmp = pq->heap[i];
pq->heap[i] = pq->heap[j];
pq->heap[j] = tmp;
}
/* Returns 1 if heap[i] has higher priority than heap[j]*/
int pq_compare(t_pqueue *pq, int i, int j)
{
if (pq->is_edf)
{
if (pq->heap[i].deadline != pq->heap[j].deadline)
return (pq->heap[i].deadline < pq->heap[j].deadline);
}
return (pq->heap[i].req_time < pq->heap[j].req_time);
}