-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_signature.c
52 lines (44 loc) · 1.48 KB
/
ft_signature.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_signature.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrophy <dbrophy@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/19 14:16:04 by dbrophy #+# #+# */
/* Updated: 2020/02/19 14:16:04 by dbrophy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** These functions act as hash functions to easily check that two objects match
**
** A modified version of neonet CRC hash is used for ft_signature_s
*/
long ft_signature_s(char *str)
{
long hash;
long a;
hash = (long)0xC59638FDF6779EA1UL;
while (*str)
{
a = hash ^ (((long)*str) << 1);
a += ((long)*str) << 16;
hash = a ^ (hash << 3);
}
return (hash);
}
long ft_signature_i(int val)
{
return (0x2809000000000000L | val);
}
long ft_signature_l(long val)
{
return (val);
}
long ft_signature_d(double val)
{
long res;
ft_memcpy(&res, &val, sizeof(long));
return (res);
}