copy on git
This commit is contained in:
commit
42653de246
205 changed files with 7459 additions and 0 deletions
79
libft/ft_hashmap/ft_hashmap_basic_cmp.c
Executable file
79
libft/ft_hashmap/ft_hashmap_basic_cmp.c
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_hashmap_basic_cmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/08 13:18:52 by thrieg #+# #+# */
|
||||
/* Updated: 2025/02/16 19:08:27 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_hashmap_private.h"
|
||||
#include <limits.h>
|
||||
|
||||
// Comparison function for integers
|
||||
int int_cmp(void *key1, void *key2)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
|
||||
a = *(int *)key1;
|
||||
b = *(int *)key2;
|
||||
if (a < b)
|
||||
return (-1);
|
||||
else if (a > b)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
// Comparison function for strings
|
||||
int cmp_str(void *key1, void *key2)
|
||||
{
|
||||
return (ft_strcmp((char *)key1, (char *)key2));
|
||||
}
|
||||
|
||||
// Comparison function for unsigned chars
|
||||
int cmp_uchar(void *key1, void *key2)
|
||||
{
|
||||
unsigned char *c1;
|
||||
unsigned char *c2;
|
||||
|
||||
c1 = (unsigned char *)key1;
|
||||
c2 = (unsigned char *)key2;
|
||||
return (*c1 - *c2);
|
||||
}
|
||||
|
||||
// Comparison function for unsigned integers
|
||||
int uint_cmp(void *key1, void *key2)
|
||||
{
|
||||
unsigned int a;
|
||||
unsigned int b;
|
||||
|
||||
a = *(unsigned int *)key1;
|
||||
b = *(unsigned int *)key2;
|
||||
if (a < b)
|
||||
return (-1);
|
||||
else if (a > b)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
// Comparison function for size_t
|
||||
int sizet_cmp(void *key1, void *key2)
|
||||
{
|
||||
size_t a;
|
||||
size_t b;
|
||||
|
||||
a = *(size_t *)key1;
|
||||
b = *(size_t *)key2;
|
||||
if (a < b)
|
||||
return (-1);
|
||||
else if (a > b)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue