/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_hashmap_basic_type_hash.c                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: thrieg <thrieg@student.42mulhouse.fr>      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/11/07 12:34:20 by thrieg            #+#    #+#             */
/*   Updated: 2025/02/16 19:08:29 by thrieg           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ft_hashmap_private.h"

// Integer hash function, returns a size_t between 0 and size_t max
size_t	ft_hash_int(int value)
{
	return ((size_t)(value * 2654435761u));
}

// Unsigned integer hash function, returns a size_t between 0 and size_t max
size_t	ft_hash_uint(unsigned int value)
{
	return ((size_t)(value * 2654435761u));
}

// Character hash function, returns a size_t between 0 and size_t max
size_t	ft_hash_char(char value)
{
	return ((size_t)(value * 31));
}

// String hash function (DJB2), returns a size_t between 0 and size_t max
size_t	ft_hash_string(const char *str)
{
	int		c;
	size_t	hash;

	hash = 5381;
	while (*str)
	{
		c = *str++;
		hash = ((hash << 5) + hash) + c;
	}
	return (hash);
}

// size_t hash function, returns a size_t between 0 and size_t max
size_t	ft_hash_size_t(size_t value)
{
	value ^= value >> 33;
	value *= 0xff51afd7ed558ccd;
	value ^= value >> 33;
	value *= 0xc4ceb9fe1a85ec53;
	value ^= value >> 33;
	return (value);
}
