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

Functions

bool hashmap_need_resize (t_hashmap *map, const char *key)
 
static void hashmap_restore (t_hashmap *map, size_t prev_size, t_vector *backup)
 
static bool hashmap_redistribution (t_hashmap *map, t_vector *prev_buckets)
 
bool hashmap_resize (t_hashmap *map)
 Doubles the bucket capacity and rehashes every stored pair.
 

Function Documentation

◆ hashmap_need_resize()

bool hashmap_need_resize ( t_hashmap map,
const char *  key 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hashmap_redistribution()

static bool hashmap_redistribution ( t_hashmap map,
t_vector prev_buckets 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hashmap_resize()

bool hashmap_resize ( t_hashmap map)

Doubles the bucket capacity and rehashes every stored pair.

Allocates a new bucket array of twice the current capacity, swaps it in and redistributes the existing pairs into it. The pairs themselves are moved, not reallocated. On failure the previous bucket array is restored, leaving the map unchanged.

Note
Pairs are transferred between bucket arrays; their keys and values are never freed by a successful resize.
Parameters
mapPointer to an initialized map (borrowed).
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:

◆ hashmap_restore()

static void hashmap_restore ( t_hashmap map,
size_t  prev_size,
t_vector backup 
)
static
Here is the call graph for this function:
Here is the caller graph for this function: