Libft
Custom implementation of core libc functions with additional utility helpers.
Loading...
Searching...
No Matches
init.c File Reference
#include "libft.h"
#include "buckets.h"
Include dependency graph for init.c:

Functions

void bucket_free (void *bucket_ptr, void(*del)(void *))
 Frees a single bucket chain and its pairs.
 
bool buckets_init (t_vector *buckets, size_t init_cap)
 Initializes the bucket array.
 
void buckets_free (t_vector *buckets, void(*del)(void *))
 Frees the bucket array and every pair it contains.
 

Function Documentation

◆ bucket_free()

void bucket_free ( void *  bucket_ptr,
void(*)(void *)  del 
)

Frees a single bucket chain and its pairs.

Frees every pair in the chain (key and, through del, value) and removes all list nodes. Shaped to be used as a buckets_foreach() callback.

Parameters
bucket_ptrAddress of the bucket slot (a t_list *) to free (borrowed).
delOptional destructor applied to each stored value (may be NULL).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ buckets_free()

void buckets_free ( t_vector buckets,
void(*)(void *)  del 
)

Frees the bucket array and every pair it contains.

Frees each bucket chain (every pair's key and, through del, its value) and then frees the underlying vector. The vector is left in a freed state.

Parameters
bucketsPointer to the bucket vector to free (borrowed).
delOptional destructor applied to each stored value (may be NULL).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ buckets_init()

bool buckets_init ( t_vector buckets,
size_t  init_cap 
)

Initializes the bucket array.

Allocates a vector of init_cap t_list slots and zeroes it, so every bucket starts as an empty (NULL) chain.

Parameters
bucketsPointer to the vector to initialize (uninitialized).
init_capNumber of buckets to allocate.
Returns
true on success, false on memory allocation failure.
Here is the call graph for this function:
Here is the caller graph for this function: