data_structures
hashset_new.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* hashset_new.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/21 18:35:49 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:57:52 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "hashset.h"
15 
17 {
18  t_hashset *hs;
19 
20  if (type->hash == NULL)
21  ds_exit_set(EINVAL);
22  hs = ds_xcalloc(sizeof(t_hashset), 1);
23  hs->vals = ds_xcalloc(sizeof(void *), HASHSET_INIT_CAPACITY);
25  hs->type = type;
26  return (hs);
27 }
hashset_new
t_hashset * hashset_new(const t_type *type)
Initializes a new empty set.
Definition: hashset_new.c:16
s_hashset::capacity
size_t capacity
The current capacity of the hashset.
Definition: hashset.h:47
ds_xcalloc
void * ds_xcalloc(size_t count, size_t size)
Replicates behaviour of calloc from libc, but fails on memory allocation errors.
Definition: ds_xcalloc.c:22
HASHSET_INIT_CAPACITY
#define HASHSET_INIT_CAPACITY
The default initial capacity of a newly initialized hashset.
Definition: hashset.h:28
hashset.h
s_hashset::vals
void ** vals
The data.
Definition: hashset.h:45
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_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
s_hashset
A dynamically resizing linear-probing hashset.
Definition: hashset.h:43
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition: ds_exit_set.c:22
s_hashset::type
const t_type * type
The type of elements in the hashset.
Definition: hashset.h:48