-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_functions.c
More file actions
64 lines (56 loc) · 1.63 KB
/
hash_functions.c
File metadata and controls
64 lines (56 loc) · 1.63 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
/* ************************************************************************** */
/* */
/* :::::::: */
/* hash_functions.c :+: :+: */
/* +:+ */
/* By: lvan-vlo <lvan-vlo@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/08/10 14:19:48 by lvan-vlo #+# #+# */
/* Updated: 2019/09/20 16:43:30 by rcorke ######## odam.nl */
/* */
/* ************************************************************************** */
#include "lem_in.h"
int lemin_list_len(t_links *list)
{
t_links *iter;
int x;
iter = list;
x = 0;
while (iter)
{
x++;
iter = iter->next;
}
return (x);
}
t_links *get_link(t_table *lem, char *str)
{
return (lem->link_table[link_index(lem, str)]);
}
int link_index(t_table *lem, char *str)
{
int hash_index;
t_hash *iter;
hash_index = lemin_hash(str, lem->rooms);
iter = lem->hash_table[hash_index];
if (!iter)
room_not_found_error(lem);
while (iter && !ft_strequ(str, iter->name))
iter = iter->next;
if (!iter)
room_not_found_error(lem);
return (iter->index);
}
int lemin_hash(char *str, int rooms)
{
int ascii;
int i;
ascii = 0;
i = 0;
while (str[i] != '\0')
{
ascii += (int)str[i];
i++;
}
return (ascii % rooms);
}