-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashtab_getentry.c
executable file
·61 lines (57 loc) · 1.99 KB
/
hashtab_getentry.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
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_getentry.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/07 11:10:25 by akharrou #+# #+# */
/* Updated: 2019/03/09 11:07:29 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** hashtab_getentry -- search and retrieve an entry.
**
** SYNOPSIS
** #include "string_42.h"
** #include "stdlib_42.h"
** #include "hashtable.h"
**
** t_entry *
** hashtab_getentry(t_hashtable *table, char *key);
**
** PARAMETERS
**
** t_hashtable *table Pointer to a hashtable.
**
** char *key Key to find the entry.
**
** DESCRIPTION
** Looks for an entry based on the 'key', if it exists returns
** a pointer to the entry.
**
** RETURN VALUES
** If the entry is found, a pointer to it is returned; otherwise
** NULL is returned.
*/
#include "../Includes/string_42.h"
#include "../Includes/stdlib_42.h"
#include "../Includes/hashtable.h"
t_entry *hashtab_getentry(t_hashtable *table, char *key)
{
t_entry *cur_entry;
unsigned int index;
if (table && key)
{
index = HASHCODE(key, table->num_buckets);
cur_entry = (table->buckets)[index];
while (cur_entry)
{
if (ft_strcmp(cur_entry->key, key) == 0)
return (cur_entry);
cur_entry = cur_entry->next;
}
}
return (NULL);
}