data_structures
hashmap_contains.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* hashmap_contains.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/21 19:53:13 by unite #+# #+# */
10 /* Updated: 2020/09/03 22:48:22 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "hashmap.h"
15 
16 int hashmap_contains(const t_hashmap *hm, const void *key)
17 {
18  size_t i;
19 
20  i = hm->key_type->hash(key, hm->capacity);
21  while (hm->keys[i] != NULL)
22  {
23  if (hm->key_type->cmp(hm->keys[i], key) == 0)
24  return (1);
25  i = (i + 1) % hm->capacity;
26  }
27  return (0);
28 }
hashmap_contains
int hashmap_contains(const t_hashmap *hm, const void *key)
Is the specified key contained in the map?
Definition: hashmap_contains.c:16
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
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