data_structures
hashmap_get.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* hashmap_get.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/21 18:59:42 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:55:03 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "hashmap.h"
15 #include "hashmap_utils.h"
16 
17 void *hashmap_get(const t_hashmap *hm, const void *key)
18 {
19  size_t i;
20 
21  i = hm->key_type->hash(key, hm->capacity);
22  while (hm->key_type->cmp(hm->keys[i], key) != 0)
23  {
24  if (hm->keys[i] == NULL)
25  return (NULL);
26  i = (i + 1) % hm->capacity;
27  }
28  return (hm->vals[i]);
29 }
hashmap_utils.h
s_hashmap::key_type
const t_type * key_type
The type of keys in the hashmap.
Definition: hashmap.h:54
s_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition: types.h:52
hashmap.h
s_hashmap::keys
void ** keys
The keys.
Definition: hashmap.h:50
hashmap_get
void * hashmap_get(const t_hashmap *hm, const void *key)
Fetches the value associated with the given key.
Definition: hashmap_get.c:17
s_type::hash
size_t(* hash)(const void *, size_t)
(optional) A function pointer used to get a hash value of this data type
Definition: types.h:53
s_hashmap
A symbol table of generic key-value pairs, implemented as a dynamically resizing linear-probing hashm...
Definition: hashmap.h:48
s_hashmap::capacity
size_t capacity
The current capacity of the hashmap.
Definition: hashmap.h:53
s_hashmap::vals
void ** vals
The values.
Definition: hashmap.h:51