Libft
Custom implementation of core libc functions with additional utility helpers.
Loading...
Searching...
No Matches
libft.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* libft.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: gastesan <gastesan@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/12/01 19:34:40 by gastesan #+# #+# */
9/* Updated: 2026/07/31 15:32:50 by gastesan ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef LIBFT_H
14# define LIBFT_H
15
16# include <stdarg.h>
17# include <stddef.h>
18# include <stdbool.h>
19# include <stdint.h>
20# include <sys/types.h>
21
22# define BUFFER_SIZE 128
23# define VECTOR_INIT_CAP 16
24
25/* ************************************************************************* */
26/* TYPES */
27/* ************************************************************************* */
28
37typedef union u_const_cast
38{
39 const char *str;
40 char *res;
42
43/* --------------------------------- T_BUFF -------------------------------- */
44
53typedef struct s_buff
54{
56 char *data;
58 size_t cap;
60 size_t len;
62
63/* -------------------------------- T_STRING ------------------------------- */
64
80typedef struct s_string
81{
84 char *data;
86 size_t cap;
88 size_t len;
90
91/* --------------------------------- T_LIST -------------------------------- */
92
101typedef struct s_node
102{
104 void *content;
106 struct s_node *prev;
108 struct s_node *next;
110
115typedef t_node *t_list;
116
117/* -------------------------------- T_BTREE -------------------------------- */
118
140
141/* -------------------------------- T_VECTOR ------------------------------- */
142
159typedef struct s_vector
160{
164 void *data;
166 size_t cap;
168 size_t len;
170 size_t item_size;
172
173/* ------------------------------- T_HASHMAP ------------------------------- */
174
176# define HASHMAP_INIT_CAP 50
177
191typedef struct s_key_value
192{
194 char *key;
196 void *value;
198
215typedef struct s_hashmap
216{
218 size_t size;
222 size_t (*hash)(const char *key);
224 void (*del_value)(void *);
226
227/* ************************************************************************* */
228/* GROUPS */
229/* ************************************************************************* */
230
324/* ************************************************************************* */
325/* BTREE */
326/* ************************************************************************* */
327
338t_btree_node *btree_new(void *data);
339
351void btree_set_left(t_btree_node *parent, t_btree_node *child);
352
364void btree_set_right(t_btree_node *parent, t_btree_node *child);
365
378
391
402void btree_free(t_btree_node **node,
403 void (*data_free)(void *data));
404
405/* ************************************************************************* */
406/* BUFF */
407/* ************************************************************************* */
408
418bool buff_adjust(t_buff *buff);
419
432bool buff_append(t_buff *dst, const t_buff *src);
433
449bool buff_append_format(t_buff *buff, const char *fstring, ...)
450 __attribute__((format(printf, 2, 3)));
451
466bool buff_append_n(t_buff *b, const char *str, long n);
467
480 t_buff *buff,
481 const char *fstring,
482 va_list args);
483
495bool buff_cmp(const t_buff *a, const t_buff *b);
496
509bool buff_dup(t_buff *dst, const t_buff *src);
510
524bool buff_dup_n(t_buff *dst, const t_buff *src, size_t n);
525
537void buff_free(t_buff *buff);
538
551void buff_free_void(void *buff);
552
563ssize_t buff_get_index_c(const t_buff *buff, char c);
564
576ssize_t buff_get_index_s(
577 const t_buff *buff,
578 const char *s,
579 ssize_t slen);
580
597char *buff_get_string(const t_buff *buff);
598
610bool buff_grow(t_buff *buff, size_t target_len);
611
629bool buff_init(
630 t_buff *buff,
631 size_t initial_cap,
632 const char *str,
633 long n);
634
649bool buff_insert(t_buff *dst, size_t index, const t_buff *src);
650
667bool buff_insert_n(t_buff *b, size_t index, const char *str,
668 long n);
669
682bool buff_prepend(t_buff *dst, const t_buff *src);
683
698bool buff_prepend_n(t_buff *b, const char *str, long n);
699
713bool buff_read_all(t_buff *buff, int fd);
714
729bool buff_read_until_c(t_buff *buff, int fd, char c);
730
745bool buff_read_until_n(t_buff *buff, int fd, size_t n);
746
761 t_buff *buff,
762 int fd,
763 const char *s,
764 ssize_t slen);
765
778void buff_rm_part(t_buff *buff, size_t i_start, ssize_t len);
779
780/* ************************************************************************* */
781/* CHR */
782/* ************************************************************************* */
783
791int ft_isalnum(int c);
792
800int ft_isalpha(int c);
801
809int ft_isascii(int c);
810
818int ft_isdigit(int c);
819
828bool ft_isincharset(char c, const char *charset);
829
837int ft_isprint(int c);
838
846int ft_isspace(char c);
847
855int ft_tolower(int c);
856
864int ft_toupper(int c);
865
866/* ************************************************************************* */
867/* CONV */
868/* ************************************************************************* */
869
877int ft_atoi(const char *str);
878
886long ft_atol(const char *str);
887
895pid_t ft_atopid(const char *str);
896
907size_t ft_atozu(const char *str);
908
918char *ft_itoa(int n);
919
929char *ft_utoa(unsigned int n);
930
940char *ft_zutoa(size_t n);
941
951char *ft_ltoa(long n);
952
962char *ft_pidtoa(pid_t n);
963
974char *ft_ultoa_base(unsigned long n, const char *base);
975
988bool parse_int(char *s, int *out);
989
1002bool parse_long(char *s, long *out);
1003
1004/* ************************************************************************* */
1005/* ERROR */
1006/* ************************************************************************* */
1007
1020void print_err(bool print_errno, const char *message);
1021
1037void fprint_err(
1038 bool print_errno,
1039 const char *safe,
1040 const char *fmt,
1041 ...)
1042 __attribute__((format(printf, 3, 4)));
1043
1044/* ************************************************************************* */
1045/* HASHMAP */
1046/* ************************************************************************* */
1047
1069bool hashmap_init(
1070 t_hashmap *map,
1071 size_t initial_cap,
1072 void (*del)(void *));
1073
1084void hashmap_free(t_hashmap *map);
1085
1098void hashmap_clear(t_hashmap *map);
1099
1129bool hashmap_put(t_hashmap *map, const char *key, void *value);
1130
1131void *hashmap_get(const t_hashmap *map, const char *key);
1132
1146const void *hashmap_get_const(const t_hashmap *map, const char *key);
1147
1165const t_key_value **hashmap_get_all(const t_hashmap *map);
1166
1180bool hashmap_remove(t_hashmap *map, const char *key);
1181
1192bool hashmap_contains(const t_hashmap *map, const char *key);
1193
1210t_key_value *key_value_new(const char *key, void *value);
1211
1223void key_value_free(t_key_value **pair, void (*del)(void *));
1224
1225/* ************************************************************************* */
1226/* LIST */
1227/* ************************************************************************* */
1228
1240t_node *node_new(void *content, t_node *prev, t_node *next);
1241
1249void node_free(t_node **node, void (*del_content)(void*));
1250
1262bool list_add_end(t_list *list, void *new_content);
1263
1275bool list_add_start(t_list *list, void *new_content);
1276
1284size_t list_get_size(t_list list);
1285
1297void *list_get_content(t_list list,
1298 bool (*select_function)(void*));
1299
1311void *list_get_content_n(t_list list, size_t index);
1312
1323void *list_get_content_last(t_list list);
1324
1336t_node *list_get_node_n(t_list list, size_t index);
1337
1349
1357void list_iter(t_list lst, void (*f)(void *));
1358
1370t_list list_map(t_list list, void *(*f)(void *),
1371 void (*del)(void *));
1372
1381void list_rm(t_list *list, t_node *node,
1382 void (*del_content)(void*));
1383
1391void list_rm_all(t_list *list, void (*del_content)(void*));
1392
1393/* ************************************************************************* */
1394/* MALLOC */
1395/* ************************************************************************* */
1396
1407void *ft_calloc(size_t count, size_t size);
1408
1420bool ft_realloc(char **buff, size_t cap, size_t newcap);
1421
1422/* ************************************************************************* */
1423/* MATH */
1424/* ************************************************************************* */
1425
1434long min(long a, long b);
1435
1444long max(long a, long b);
1445
1453size_t absolute(long nbr);
1454
1468long power(int a, int b);
1469
1480size_t modulo(long a, size_t b);
1481
1489int square_root_exact(int nb);
1490
1498int square_root_rounded(int nb);
1499
1500/* ************************************************************************* */
1501/* MEM */
1502/* ************************************************************************* */
1503
1511void ft_bzero(void *s, size_t n);
1512
1524void *ft_memchr(const void *s, int c, size_t n);
1525
1535int ft_memcmp(const void *s1, const void *s2, size_t n);
1536
1548void *ft_memcpy(void *dst, const void *src, size_t n);
1549
1559void *ft_memmove(void *dst, const void *src, size_t len);
1560
1570void *ft_memset(void *b, int c, size_t len);
1571
1572/* ************************************************************************* */
1573/* PRINT */
1574/* ************************************************************************* */
1575
1585int ft_vdprintf(int fd, const char *fstring, va_list args);
1586
1600int ft_dprintf(int fd, const char *fstring, ...)
1601 __attribute__((format(printf, 2, 3)));
1602
1611int ft_vprintf(const char *fstring, va_list args);
1612
1625int ft_printf(const char *fstring, ...)
1626 __attribute__((format(printf, 1, 2)));
1627
1628/* ************************************************************************* */
1629/* PUT */
1630/* ************************************************************************* */
1631
1638void ft_putchar_fd(char c, int fd);
1639
1647void ft_putendl_fd(char *s, int fd);
1648
1656void ft_putnbr_fd(int n, int fd);
1657
1665void ft_putstr_fd(char *s, int fd);
1666
1667/* ************************************************************************* */
1668/* STR */
1669/* ************************************************************************* */
1670
1678void str_array_free(char ***tab_ptr);
1679
1691char *str_chr(const char *s, int c);
1692
1701int str_cmp(const char *s1, const char *s2);
1702
1710size_t str_count_words(char const *s, char sep);
1711
1721char *str_dup(const char *s1);
1722
1730void str_iteri(char *s, void (*f)(unsigned int, char*));
1731
1742char *str_join(char const *s1, char const *s2);
1743
1753size_t str_lcat(char *dst, const char *src, size_t dstsize);
1754
1764size_t str_lcpy(char *dst, const char *src, size_t dstsize);
1765
1773size_t str_len(const char *s);
1774
1785char *str_mapi(char const *s, char (*f)(unsigned int, char));
1786
1796int str_ncmp(const char *s1, const char *s2, size_t n);
1797
1808char *str_ndup(const char *src, size_t len);
1809
1821char *str_nstr(const char *haystack, const char *needle,
1822 size_t len);
1823
1835char *str_rchr(const char *s, int c);
1836
1848char **str_split(char const *s, char c);
1849
1861char *str_sub(char const *s, unsigned int start, size_t len);
1862
1873char *str_trim(char const *s1, char const *set);
1874
1875char *str_trim_leading(char const *s1, char const *set);
1876
1877/* ************************************************************************* */
1878/* STRING */
1879/* ************************************************************************* */
1880
1890bool string_adjust(t_string *string);
1891
1904bool string_append(t_string *dst, const t_string *src);
1905
1920 t_string *string, const char *fstring, ...)
1921 __attribute__((format(printf, 2, 3)));
1922
1937bool string_append_n(t_string *s, const char *str, long n);
1938
1951 t_string *string,
1952 const char *fstring,
1953 va_list args);
1954
1966bool string_cmp(const t_string *a, const t_string *b);
1967
1981bool string_dup(t_string *dst, const t_string *src);
1982
1997bool string_dup_n(t_string *dst, const t_string *src, size_t n);
1998
2011void string_free(t_string *string);
2012
2025void string_free_void(void *string);
2026
2037ssize_t string_get_index_c(const t_string *string, char c);
2038
2050ssize_t string_get_index_s(
2051 const t_string *string,
2052 const char *s,
2053 ssize_t slen);
2054
2066bool string_grow(t_string *string, size_t target_cap);
2067
2089bool string_init(
2090 t_string *s,
2091 size_t initial_cap,
2092 const char *str,
2093 long n);
2094
2109bool string_insert(t_string *dst, size_t index,
2110 const t_string *src);
2111
2128bool string_insert_n(
2129 t_string *s,
2130 size_t index,
2131 const char *str,
2132 long n);
2133
2146bool string_prepend(t_string *dst, const t_string *src);
2147
2162bool string_prepend_n(t_string *s, const char *str, long n);
2163
2177bool string_read_all(t_string *string, int fd);
2178
2193bool string_read_until_c(t_string *string, int fd, char c);
2194
2209bool string_read_until_n(t_string *string, int fd, size_t n);
2210
2227 t_string *string,
2228 int fd,
2229 const char *s,
2230 ssize_t slen);
2231
2244void string_rm_part(t_string *string, size_t i_start,
2245 ssize_t len);
2246
2266bool string_split_at(
2267 const t_string *src,
2268 size_t index,
2269 t_string *out_before,
2270 t_string *out_after);
2271
2296 const t_string *src,
2297 char c,
2298 bool keep_empty_entries,
2299 t_vector *out);
2300
2328 const t_string *src,
2329 const char *sep,
2330 bool keep_empty_entries,
2331 t_vector *out);
2332
2349void string_take(t_string *dst, char *src, size_t cap,
2350 ssize_t len);
2351
2370void string_take_string(t_string *dst, t_string *src);
2371
2383void string_trim_leading(t_string *string, char c);
2384
2385/* ************************************************************************* */
2386/* VECTOR */
2387/* ************************************************************************* */
2388
2404bool vector_init(t_vector *vector, size_t item_size, size_t cap);
2405
2418bool vector_grow(t_vector *vector);
2419
2432bool vector_adjust(t_vector *vector);
2433
2452bool vector_dup(t_vector *dst, const t_vector *src);
2453
2468void vector_free(t_vector *vector,
2469 void (*item_free)(void *item));
2470
2485void vector_clear(t_vector *vector, void (*del)(void *));
2486
2500bool vector_push(t_vector *vector, const void *item);
2501
2515bool vector_pop(t_vector *vector, void *dst);
2516
2532bool vector_insert(t_vector *vector, size_t index,
2533 const void *item);
2534
2550bool vector_remove(t_vector *vector, size_t index, void *dst);
2551
2565void vector_take(t_vector *dst, t_vector *src);
2566
2584bool vector_merge(t_vector *dst, const t_vector *src,
2585 size_t index);
2586
2587#endif
t_btree_node * btree_new(void *data)
Creates a new binary tree node.
Definition btree.c:16
void btree_set_left(t_btree_node *parent, t_btree_node *child)
Sets the left child of a parent node.
Definition btree.c:30
void btree_free(t_btree_node **node, void(*data_free)(void *data))
Recursively frees a node and its descendants.
Definition btree_free.c:16
t_btree_node * btree_detach_left(t_btree_node *parent)
Detaches and returns the left child of a parent node.
Definition btree.c:42
t_btree_node * btree_detach_right(t_btree_node *parent)
Detaches and returns the right child of a parent node.
Definition btree.c:52
void btree_set_right(t_btree_node *parent, t_btree_node *child)
Sets the right child of a parent node.
Definition btree.c:36
bool buff_insert_n(t_buff *b, size_t index, const char *str, long n)
Inserts n first bytes of a string in the buffer at specified index.
Definition buff_ops_n.c:46
bool buff_adjust(t_buff *buff)
Shrinks buffer capacity to match its current length.
Definition buff_utils.c:16
ssize_t buff_get_index_s(const t_buff *buff, const char *s, ssize_t slen)
Finds the first occurrence of a substring in the buffer.
Definition buff_utils.c:54
bool buff_prepend_n(t_buff *b, const char *str, long n)
Prepends n first bytes of a string to the beginning of the buffer.
Definition buff_ops_n.c:17
void buff_free(t_buff *buff)
Frees the buffer's internal data.
Definition buff_life_cycle.c:33
ssize_t buff_get_index_c(const t_buff *buff, char c)
Finds the index of the first occurrence of a character in the buffer.
Definition buff_utils.c:40
bool buff_read_all(t_buff *buff, int fd)
Reads all available data from a file descriptor into buffer.
Definition buff_read.c:50
void buff_free_void(void *buff)
Frees a t_buff item through a generic void* callback signature.
Definition buff_life_cycle.c:42
bool buff_read_until_n(t_buff *buff, int fd, size_t n)
Reads up to n bytes from a file descriptor into buffer.
Definition buff_read.c:39
void buff_rm_part(t_buff *buff, size_t i_start, ssize_t len)
Removes a portion of the buffer starting at i_start.
Definition buff_ops.c:36
bool buff_prepend(t_buff *dst, const t_buff *src)
Prepends a source buffer to the beginning of a buffer.
Definition buff_ops.c:16
char * buff_get_string(const t_buff *buff)
Returns a newly allocated copy of the buffer content.
Definition buff_utils.c:80
bool buff_append_format(t_buff *buff, const char *fstring,...)
Appends formatted string to buffer using variadic arguments.
Definition buff_format.c:16
bool buff_append_n(t_buff *b, const char *str, long n)
Appends n first bytes of a string to the end of the buffer.
Definition buff_ops_n.c:75
bool buff_append_vformat(t_buff *buff, const char *fstring, va_list args)
Appends formatted string to buffer using va_list.
Definition buff_format.c:27
bool buff_init(t_buff *buff, size_t initial_cap, const char *str, long n)
Initializes a buffer with the specified initial capacity.
Definition buff_life_cycle.c:16
bool buff_insert(t_buff *dst, size_t index, const t_buff *src)
Inserts a source buffer in a buffer at the specified index.
Definition buff_ops.c:21
bool buff_dup_n(t_buff *dst, const t_buff *src, size_t n)
Copies up to n bytes from a source buffer into an existing buffer.
Definition buff_ops_n.c:92
bool buff_read_until_s(t_buff *buff, int fd, const char *s, ssize_t slen)
Reads from a file descriptor until a specific substring is found.
Definition buff_read_until_s.c:76
bool buff_cmp(const t_buff *a, const t_buff *b)
Compares two buffers data byte by byte.
Definition buff_cmp.c:15
bool buff_dup(t_buff *dst, const t_buff *src)
Copies the content of a source buffer into an existing buffer.
Definition buff_ops.c:31
bool buff_append(t_buff *dst, const t_buff *src)
Appends the content of a source buffer to the end of a buffer.
Definition buff_ops.c:26
bool buff_read_until_c(t_buff *buff, int fd, char c)
Reads from a file descriptor until a specific character is found.
Definition buff_read.c:19
int ft_isdigit(int c)
Checks if a character is a digit ('0'-'9').
Definition ft_isdigit.c:13
bool ft_isincharset(char c, const char *charset)
Checks if a character is present in a character set.
Definition ft_isincharset.c:15
int ft_isalnum(int c)
Checks if a character is alphanumeric.
Definition ft_isalnum.c:13
int ft_tolower(int c)
Converts an uppercase letter to lowercase.
Definition ft_tolower.c:13
int ft_isprint(int c)
Checks if a character is printable (32-126).
Definition ft_isprint.c:13
int ft_isascii(int c)
Checks if a character is a valid ASCII character (0-127).
Definition ft_isascii.c:13
int ft_isalpha(int c)
Checks if a character is alphabetic.
Definition ft_isalpha.c:13
int ft_isspace(char c)
Checks if a character is whitespace (9-13).
Definition ft_isspace.c:13
int ft_toupper(int c)
Converts a lowercase letter to uppercase.
Definition ft_toupper.c:13
long ft_atol(const char *str)
Converts a string to a long integer.
Definition ft_atol.c:15
pid_t ft_atopid(const char *str)
Converts a string to a pid_t.
Definition ft_atopid.c:16
char * ft_ultoa_base(unsigned long n, const char *base)
Converts an unsigned long to a string in a given base.
Definition ft_ultoa_base.c:18
bool parse_int(char *s, int *out)
Parses a string to an integer with overflow detection.
Definition parse_int.c:16
char * ft_zutoa(size_t n)
Converts a size_t to a string.
Definition ft_zutoa.c:18
char * ft_itoa(int n)
Converts an integer to a string.
Definition variants.c:20
char * ft_ltoa(long n)
Converts a long integer to a string.
Definition ft_ltoa.c:18
char * ft_pidtoa(pid_t n)
Converts a pid_t to a string.
Definition ft_pidtoa.c:19
size_t ft_atozu(const char *str)
Converts a string to a size_t.
Definition ft_atozu.c:16
bool parse_long(char *s, long *out)
Parses a string to a long with overflow detection.
Definition parse_long.c:16
char * ft_utoa(unsigned int n)
Converts an unsigned integer to a string.
Definition variants.c:25
int ft_atoi(const char *str)
Converts a string to an integer.
Definition variants.c:15
void print_err(bool print_errno, const char *message)
Prints "Error\n" to stderr with optional message and errno.
Definition error.c:39
void fprint_err(bool print_errno, const char *safe, const char *fmt,...)
Prints "Error\n" to stderr with safe prefix + formatted suffix.
Definition error.c:22
bool hashmap_contains(const t_hashmap *map, const char *key)
Tests whether a key is present in the map.
Definition contains.c:16
bool hashmap_put(t_hashmap *map, const char *key, void *value)
Inserts a key/value pair, replacing any existing value for the key.
Definition put.c:16
t_key_value * key_value_new(const char *key, void *value)
Allocates a key/value pair.
Definition init.c:16
bool hashmap_remove(t_hashmap *map, const char *key)
Removes the pair associated with a key.
Definition remove.c:16
void hashmap_free(t_hashmap *map)
Frees a hash map and all of its contents.
Definition init.c:27
void key_value_free(t_key_value **pair, void(*del)(void *))
Frees a key/value pair and its contents.
Definition init.c:29
const t_key_value ** hashmap_get_all(const t_hashmap *map)
Collects every key/value pair stored in the map.
Definition get.c:38
bool hashmap_init(t_hashmap *map, size_t initial_cap, void(*del)(void *))
Initializes an empty hash map.
Definition init.c:17
const void * hashmap_get_const(const t_hashmap *map, const char *key)
Retrieves the value associated with a key.
Definition get.c:33
void hashmap_clear(t_hashmap *map)
Removes all key/value pairs from a hash map.
Definition init.c:33
t_list list_map(t_list list, void *(*f)(void *), void(*del)(void *))
Creates a new list by applying a function to each element.
Definition list_apply.c:30
void * list_get_content(t_list list, bool(*select_function)(void *))
Finds content in list matching a selection function.
Definition list_get.c:16
void list_iter(t_list lst, void(*f)(void *))
Applies a function to each element of the list.
Definition list_apply.c:16
size_t list_get_size(t_list list)
Calculates the number of nodes in the list.
Definition list_size.c:15
void * list_get_content_n(t_list list, size_t index)
Gets content at a specific index in the list.
Definition list_get.c:32
bool list_add_end(t_list *list, void *new_content)
Adds a new element at the end of the list.
Definition list_life_cycle.c:31
void list_rm(t_list *list, t_node *node, void(*del_content)(void *))
Removes a specific node from the list.
Definition list_life_cycle.c:54
t_node * list_get_node_last(t_list list)
Gets the last node in the list.
Definition list_get.c:69
t_node * node_new(void *content, t_node *prev, t_node *next)
Creates a new list node.
Definition node.c:16
void node_free(t_node **node, void(*del_content)(void *))
Frees a node and optionally its content.
Definition node.c:29
bool list_add_start(t_list *list, void *new_content)
Adds a new element at the start of the list.
Definition list_life_cycle.c:16
void list_rm_all(t_list *list, void(*del_content)(void *))
Removes all nodes from the list.
Definition list_life_cycle.c:74
void * list_get_content_last(t_list list)
Gets the content of the last node in the list.
Definition list_get.c:42
t_node * list_get_node_n(t_list list, size_t index)
Gets the node at a specific index in the list.
Definition list_get.c:52
bool ft_realloc(char **buff, size_t cap, size_t newcap)
Reallocates a buffer to a new capacity.
Definition ft_realloc.c:16
void * ft_calloc(size_t count, size_t size)
Allocates and zeroes memory for an array.
Definition ft_calloc.c:17
long min(long a, long b)
Returns the minimum of two long integers.
Definition min_max_abs.c:15
int square_root_exact(int nb)
Calculates the exact integer square root.
Definition square_root.c:13
size_t modulo(long a, size_t b)
Computes the modulo of a signed integer with an unsigned modulus.
Definition modulo.c:15
long max(long a, long b)
Returns the maximum of two long integers.
Definition min_max_abs.c:23
int square_root_rounded(int nb)
Calculates the nearest integer square root.
Definition square_root.c:29
long power(int a, int b)
Computes a raised to the power of b.
Definition power.c:13
size_t absolute(long nbr)
Returns the absolute value of a long integer.
Definition min_max_abs.c:31
int ft_memcmp(const void *s1, const void *s2, size_t n)
Compares two memory areas byte by byte.
Definition ft_memcmp.c:15
void * ft_memset(void *b, int c, size_t len)
Fills memory with a constant byte.
Definition ft_memset.c:15
void ft_bzero(void *s, size_t n)
Sets n bytes of memory to zero.
Definition ft_bzero.c:15
void * ft_memcpy(void *dst, const void *src, size_t n)
Copies n bytes from src to dst.
Definition ft_memcpy.c:15
void * ft_memchr(const void *s, int c, size_t n)
Locates the first occurrence of a byte in memory.
Definition ft_memchr.c:15
void * ft_memmove(void *dst, const void *src, size_t len)
Copies n bytes from src to dst, handling overlapping memory.
Definition ft_memmove.c:15
int ft_dprintf(int fd, const char *fstring,...)
Writes formatted output to a file descriptor.
Definition printer.c:35
int ft_vprintf(const char *fstring, va_list args)
Writes formatted output to stdout using va_list.
Definition printer.c:48
int ft_printf(const char *fstring,...)
Writes formatted output to stdout.
Definition printer.c:53
int ft_vdprintf(int fd, const char *fstring, va_list args)
Writes formatted output to a file descriptor using va_list.
Definition printer.c:18
void ft_putnbr_fd(int n, int fd)
Writes an integer to a file descriptor.
Definition ft_putnbr_fd.c:17
void ft_putstr_fd(char *s, int fd)
Writes a string to a file descriptor.
Definition ft_putstr_fd.c:16
void ft_putendl_fd(char *s, int fd)
Writes a string followed by newline to a file descriptor.
Definition ft_putendl_fd.c:16
char ** str_split(char const *s, char c)
Splits a string into an array of strings using a delimiter.
Definition str_split.c:18
char * str_join(char const *s1, char const *s2)
Concatenates two strings into a new string.
Definition str_join.c:16
size_t str_lcat(char *dst, const char *src, size_t dstsize)
Appends src to dst with size limit.
Definition str_lcat.c:15
size_t str_len(const char *s)
Calculates the length of a string.
Definition str_len.c:15
size_t str_lcpy(char *dst, const char *src, size_t dstsize)
Copies src to dst with size limit.
Definition str_lcpy.c:15
char * str_mapi(char const *s, char(*f)(unsigned int, char))
Creates a new string by applying a function to each character.
Definition str_mapi.c:16
char * str_ndup(const char *src, size_t len)
Duplicates the first len bytes of a string.
Definition str_ndup.c:15
char * str_nstr(const char *haystack, const char *needle, size_t len)
Locates a substring within a string, limited by length.
Definition str_nstr.c:15
char * str_sub(char const *s, unsigned int start, size_t len)
Extracts a substring from a string.
Definition str_sub.c:16
char * str_rchr(const char *s, int c)
Locates the last occurrence of a character in a string.
Definition str_rchr.c:15
char * str_chr(const char *s, int c)
Locates the first occurrence of a character in a string.
Definition str_chr.c:15
void str_iteri(char *s, void(*f)(unsigned int, char *))
Applies a function to each character of a string with its index.
Definition str_iteri.c:13
char * str_trim(char const *s1, char const *set)
Trims characters from the beginning and end of a string.
Definition str_trim.c:18
char * str_dup(const char *s1)
Duplicates a string.
Definition str_dup.c:16
int str_cmp(const char *s1, const char *s2)
Compares two strings.
Definition str_cmp.c:15
int str_ncmp(const char *s1, const char *s2, size_t n)
Compares at most n characters of two strings.
Definition str_ncmp.c:15
bool string_adjust(t_string *string)
Shrinks string capacity to match its current length plus NUL byte.
Definition string_utils.c:16
void string_trim_leading(t_string *string, char c)
Removes leading copies of a character from a string.
Definition string_ops_n.c:107
bool string_prepend(t_string *dst, const t_string *src)
Prepends a source string to the beginning of a string.
Definition string_ops.c:16
ssize_t string_get_index_c(const t_string *string, char c)
Finds the index of the first occurrence of a character in the string.
Definition string_utils.c:38
void string_rm_part(t_string *string, size_t i_start, ssize_t len)
Removes a portion of the string starting at i_start.
Definition string_ops.c:39
bool string_read_until_n(t_string *string, int fd, size_t n)
Reads up to n bytes from a file descriptor into string.
Definition string_read.c:42
void string_take(t_string *dst, char *src, size_t cap, ssize_t len)
Installs an existing buffer in a string without copying it.
Definition string_life_cycle.c:37
bool string_split_at(const t_string *src, size_t index, t_string *out_before, t_string *out_after)
Splits a string into two initialized strings at a byte index.
Definition string_split_at.c:15
bool string_dup_n(t_string *dst, const t_string *src, size_t n)
Copies up to n bytes from a source string into an existing string.
Definition string_ops_n.c:92
bool string_prepend_n(t_string *s, const char *str, long n)
Prepends n first bytes of a string to the beginning of a string.
Definition string_ops_n.c:17
bool string_cmp(const t_string *a, const t_string *b)
Compares two strings byte by byte.
Definition string_cmp.c:15
bool string_split_on_char(const t_string *src, char c, bool keep_empty_entries, t_vector *out)
Splits a string on a delimiter character into a t_vector.
Definition string_split_on_char.c:68
bool string_append_vformat(t_string *string, const char *fstring, va_list args)
Appends formatted text to string using va_list.
Definition string_format.c:28
void string_free_void(void *string)
Frees a t_string item through a generic void* callback signature.
Definition string_life_cycle.c:62
bool string_init(t_string *s, size_t initial_cap, const char *str, long n)
Initializes a string with the specified initial capacity.
Definition string_life_cycle.c:16
bool string_dup(t_string *dst, const t_string *src)
Copies the content of a source string into an existing string.
Definition string_ops.c:34
bool string_read_until_s(t_string *string, int fd, const char *s, ssize_t slen)
Reads from a file descriptor until a specific substring is found.
Definition string_read_until_s.c:76
ssize_t string_get_index_s(const t_string *string, const char *s, ssize_t slen)
Finds the first occurrence of a substring in the string.
Definition string_utils.c:52
void string_free(t_string *string)
Frees the string's internal data.
Definition string_life_cycle.c:53
void string_take_string(t_string *dst, t_string *src)
Move the internal storage of one string into another string.
Definition string_life_cycle.c:47
bool string_read_until_c(t_string *string, int fd, char c)
Reads from a file descriptor until a specific character is found.
Definition string_read.c:19
bool string_append(t_string *dst, const t_string *src)
Appends the content of a source string to the end of a string.
Definition string_ops.c:29
bool string_append_format(t_string *string, const char *fstring,...)
Appends formatted text to string using variadic arguments.
Definition string_format.c:16
bool string_read_all(t_string *string, int fd)
Reads all available data from a file descriptor into string.
Definition string_read.c:54
bool string_insert(t_string *dst, size_t index, const t_string *src)
Inserts a source string in a string at the specified index.
Definition string_ops.c:21
bool string_append_n(t_string *s, const char *str, long n)
Appends n first bytes of a string to the end of a dynamic string.
Definition string_ops_n.c:75
bool string_split_on_string(const t_string *src, const char *sep, bool keep_empty_entries, t_vector *out)
Splits a string on a delimiter C-string into a t_vector.
Definition string_split_on_string.c:76
bool string_insert_n(t_string *s, size_t index, const char *str, long n)
Inserts n first bytes of a string at the specified index.
Definition string_ops_n.c:46
bool vector_dup(t_vector *dst, const t_vector *src)
Duplicates a vector into another one.
Definition vector_life_cycle.c:81
bool vector_grow(t_vector *vector)
Grows vector capacity, usually by doubling it.
Definition vector_life_cycle.c:36
bool vector_push(t_vector *vector, const void *item)
Appends one item at the end of the vector.
Definition vector_ops_items.c:19
bool vector_pop(t_vector *vector, void *dst)
Removes the last item from the vector.
Definition vector_ops_items.c:32
void vector_free(t_vector *vector, void(*item_free)(void *item))
Frees the vector's internal storage.
Definition vector_life_cycle.c:95
bool vector_insert(t_vector *vector, size_t index, const void *item)
Inserts one item at a specific index.
Definition vector_ops_items.c:45
void vector_take(t_vector *dst, t_vector *src)
Transfers a vector state into another one without copying items.
Definition vector_ops_vectors.c:113
bool vector_merge(t_vector *dst, const t_vector *src, size_t index)
Inserts all items from src into dst at a specific index.
Definition vector_ops_vectors.c:20
bool vector_adjust(t_vector *vector)
Shrinks vector capacity to match its current length.
Definition vector_life_cycle.c:59
bool vector_remove(t_vector *vector, size_t index, void *dst)
Removes one item at a specific index.
Definition vector_ops_items.c:94
void vector_clear(t_vector *vector, void(*del)(void *))
Removes all items from a vector without freeing its storage.
Definition vector_ops_vectors.c:47
bool vector_init(t_vector *vector, size_t item_size, size_t cap)
Initializes a vector with a given item size and initial capacity.
Definition vector_life_cycle.c:17
struct s_buff t_buff
bool buff_grow(t_buff *buff, size_t target_len)
Grows the buffer to accommodate the target length if necessary.
Definition buff_internal.c:37
union u_const_cast t_const_cast
Temporary pointer view used to reinterpret the same address with or without const qualification.
struct s_node t_node
struct s_btree_node t_btree_node
t_node * t_list
Type alias for a pointer to a list node (list head).
Definition libft.h:115
size_t str_count_words(char const *s, char sep)
Counts words in a string separated by a delimiter.
Definition str_split.c:47
struct s_key_value t_key_value
void str_array_free(char ***tab_ptr)
Frees all strings in a null-terminated array and the tab itself.
Definition str_split.c:87
void * hashmap_get(const t_hashmap *map, const char *key)
Definition get.c:17
char * str_trim_leading(char const *s1, char const *set)
Definition str_trim_leading.c:18
void ft_putchar_fd(char c, int fd)
Writes a character to a file descriptor.
Definition ft_putchar_fd.c:15
bool string_grow(t_string *string, size_t target_cap)
Grows the string to accommodate the target length if necessary.
Definition string_internal.c:37
struct s_hashmap t_hashmap
struct s_string t_string
struct s_vector t_vector
Binary tree node structure.
Definition libft.h:130
void * data
Pointer to node payload (owned by the node, may be NULL).
Definition libft.h:138
struct s_btree_node * parent
Pointer to the parent node (borrowed, may be NULL).
Definition libft.h:132
struct s_btree_node * left
Pointer to the left child (borrowed, may be NULL).
Definition libft.h:134
struct s_btree_node * right
Pointer to the right child (borrowed, may be NULL).
Definition libft.h:136
Dynamic buffer structure for efficient string/data manipulation.
Definition libft.h:54
size_t cap
Current allocated capacity (in bytes).
Definition libft.h:58
size_t len
Current length of data in the buffer (in bytes).
Definition libft.h:60
char * data
Pointer to the allocated data (owned).
Definition libft.h:56
Separate-chaining hash map keyed by NUL-terminated strings.
Definition libft.h:216
t_vector buckets
Vector of t_list buckets (owned by the map).
Definition libft.h:220
size_t(* hash)(const char *key)
Hash function applied to keys (defaults to hash_string).
Definition libft.h:222
size_t size
Current number of stored key/value pairs.
Definition libft.h:218
void(* del_value)(void *)
Optional destructor for stored values (may be NULL).
Definition libft.h:224
Key/value pair stored inside a hashmap bucket.
Definition libft.h:192
char * key
Heap-allocated copy of the key string (owned by the pair).
Definition libft.h:194
void * value
Pointer to the stored value (owned by the pair).
Definition libft.h:196
Doubly linked list node structure.
Definition libft.h:102
void * content
Pointer to the node's content (owned by the node).
Definition libft.h:104
struct s_node * next
Pointer to the next node (borrowed, may be NULL).
Definition libft.h:108
struct s_node * prev
Pointer to the previous node (borrowed, may be NULL).
Definition libft.h:106
Dynamic string structure with NUL-terminated storage.
Definition libft.h:81
size_t len
Current length in bytes, excluding the trailing NUL.
Definition libft.h:88
char * data
Pointer to the string storage (borrowed or owned, NUL-terminated if not NULL).
Definition libft.h:84
size_t cap
Current capacity in bytes, also encoding storage ownership.
Definition libft.h:86
Dynamic array storing contiguous fixed-size items.
Definition libft.h:160
size_t len
Current number of stored items, expressed in items.
Definition libft.h:168
void * data
Pointer to the contiguous array of items (borrowed or owned by the vector, may be NULL).
Definition libft.h:164
size_t item_size
Size of each item, expressed in bytes.
Definition libft.h:170
size_t cap
Current capacity in items, also encoding storage ownership.
Definition libft.h:166
Temporary pointer view used to reinterpret the same address with or without const qualification.
Definition libft.h:38
const char * str
Definition libft.h:39
char * res
Definition libft.h:40