/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   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);
}
