codexion / src / scheduler / heap_utils.c 60 commits
07-07-2026
35 lines 1.2 kB
 1/* ************************************************************************** */
 2/*                                                                            */
 3/*                                                        :::      ::::::::   */
 4/*   heap_utils.c                                       :+:      :+:    :+:   */
 5/*                                                    +:+ +:+         +:+     */
 6/*   By: mleitao <marvin@42.fr>                     +#+  +:+       +#+        */
 7/*                                                +#+#+#+#+#+   +#+           */
 8/*   Created: 2026/07/07 00:39:10 by mleitao           #+#    #+#             */
 9/*   Updated: 2026/07/07 00:40:04 by mleitao          ###   ########.fr       */
10/*                                                                            */
11/* ************************************************************************** */
12
13#include "heap.h"
14#include <stdlib.h>
15
16int	heap_init(t_heap *h, unsigned int cap)
17{
18	h->size = 0;
19	h->arr = malloc(sizeof(t_req) * cap);
20	if (!h->arr)
21		return (-1);
22	return (0);
23}
24
25void	heap_free(t_heap *h)
26{
27	free(h->arr);
28	h->arr = NULL;
29	h->size = 0;
30}
31
32t_req	heap_peek(const t_heap *h)
33{
34	return (h->arr[0]);
35}