/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_hashmap_advanced_type_hash.c                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: thrieg <thrieg@student.42mulhouse.fr>      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/11/07 12:47:23 by thrieg            #+#    #+#             */
/*   Updated: 2025/02/16 19:08:26 by thrieg           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ft_hashmap_private.h"
#include <stdint.h>

//hash function for an address, returns a size_t between 0 and size_t max
size_t	ft_hash_address(const void *key)
{
	uintptr_t	address;

	address = (uintptr_t)key;
	return ((size_t)address >> 3);
}

// Hash function for a t_list, returns a size_t between 0 and size_t max
//takes the function to hash a single element
size_t	ft_hash_list(const t_list *list)
{
	return (ft_hash_address(list));
}

// Hash function for a t_hashmap, returns a size_t between 0 and size_t max
size_t	ft_hash_hashmap(const t_hashmap *hashmap)
{
	return (ft_hash_address(hashmap));
}

// Hash function for a t_vector, returns a size_t between 0 and size_t max
size_t	ft_hash_vector(const t_vector *vec)
{
	size_t	i;
	int		c;
	size_t	index;
	size_t	hash;
	char	*str;

	hash = 5381;
	index = vec->index;
	str = vec->buffer;
	i = 0;
	while (i < index)
	{
		c = str[i++];
		hash = ((hash << 5) + hash) + c;
	}
	return (hash);
}
