|
Libft
Custom implementation of core libc functions with additional utility helpers.
|
#include "libft.h"

Go to the source code of this file.
Functions | |
| 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. | |
| void | buckets_detach (t_vector *buckets) |
| Detaches every pair from the bucket chains without freeing them. | |
| void | buckets_swap (t_vector *buckets1, t_vector *buckets2) |
| Swaps the contents of two bucket vectors. | |
| void | buckets_foreach (t_vector *vector, void(*del)(void *), void(*f)(void *, void(*del)(void *))) |
| Applies a function to every used bucket slot. | |
| void | bucket_free (void *bucket_ptr, void(*del)(void *)) |
| Frees a single bucket chain and its pairs. | |
| bool | bucket_contains (t_list bucket, const char *key) |
| Tests whether a bucket chain holds a pair with the given key. | |
| void | bucket_detach (void *bucket, void(*_)(void *)) |
| Detaches every pair from a single bucket chain without freeing them. | |
| void | bucket_replace (t_list bucket, t_key_value *new, void(*del)(void *)) |
| Replaces the value of the pair matching new->key within a chain. | |
| bool bucket_contains | ( | t_list | bucket, |
| const char * | key | ||
| ) |
Tests whether a bucket chain holds a pair with the given key.
| bucket | Head of the bucket chain to search (borrowed, may be NULL). |
| key | NUL-terminated key to look for (borrowed). |


| void bucket_detach | ( | void * | bucket, |
| void(*)(void *) | _ | ||
| ) |
Detaches every pair from a single bucket chain without freeing them.
Sets each node's content to NULL. Shaped to be used as a buckets_foreach() callback; the destructor parameter is unused.
| bucket | Address of the bucket slot (a t_list *) to detach (borrowed). |
| _ | Unused destructor parameter (required by the callback signature). |

| 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.
| bucket_ptr | Address of the bucket slot (a t_list *) to free (borrowed). |
| del | Optional destructor applied to each stored value (may be NULL). |


| void bucket_replace | ( | t_list | bucket, |
| t_key_value * | new, | ||
| void(*)(void *) | del | ||
| ) |
Replaces the value of the pair matching new->key within a chain.
Walks the chain and, for the node whose key matches new->key, releases the existing pair (its value through del) and stores new in its place.
| bucket | Head of the bucket chain to update (borrowed). |
| new | Replacement pair carrying the matching key (ownership transferred). |
| del | Optional destructor applied to the replaced value (may be NULL). |


| void buckets_detach | ( | t_vector * | buckets | ) |
Detaches every pair from the bucket chains without freeing them.
Sets each list node's content to NULL across all buckets, severing the link between the chains and their pairs. Used during a resize so the old chains can be freed while the pairs themselves are kept (they have been moved into the new bucket array).
| buckets | Pointer to the bucket vector to detach (borrowed). |


| void buckets_foreach | ( | t_vector * | vector, |
| void(*)(void *) | del, | ||
| void(*)(void *, void(*del)(void *)) | f | ||
| ) |
Applies a function to every used bucket slot.
Iterates over the first vector->len slots and calls f with the address of each bucket slot and the del callback, allowing f to free or mutate the chain stored there.
| vector | Pointer to the bucket vector to iterate (borrowed). |
| del | Destructor forwarded to f for each slot (may be NULL). |
| f | Function applied to each bucket slot (borrowed). |

| 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.
| buckets | Pointer to the bucket vector to free (borrowed). |
| del | Optional destructor applied to each stored value (may be NULL). |


| 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.
| buckets | Pointer to the vector to initialize (uninitialized). |
| init_cap | Number of buckets to allocate. |


Swaps the contents of two bucket vectors.
Exchanges the two t_vector structures by value; no allocation occurs and no pair is moved in memory.
| buckets1 | First bucket vector (borrowed). |
| buckets2 | Second bucket vector (borrowed). |
