data_structures
hashset.h
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* hashset.h :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/21 18:15:39 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:36:25 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #ifndef HASHSET_H
15 
16 # define HASHSET_H
17 
18 # include <errno.h>
19 # include <sys/types.h>
20 # include "types.h"
21 # include "queue.h"
22 # include "utils.h"
23 
28 # define HASHSET_INIT_CAPACITY 51
29 
43 typedef struct s_hashset
44 {
45  void **vals;
46  size_t size;
47  size_t capacity;
48  const t_type *type;
49 } t_hashset;
50 
59 t_hashset *hashset_new(const t_type *type);
60 
66 void hashset_put(t_hashset *hs, const void *val);
67 
73 t_queue *hashset_vals(const t_hashset *hs);
74 
80 size_t hashset_size(const t_hashset *hs);
81 
87 void hashset_delete(t_hashset *hs);
88 
95 int hashset_contains(const t_hashset *hs, const void *val);
96 
103 void hashset_remove(t_hashset *hs, const void *val);
104 
110 t_hashset *hashset_copy(const t_hashset *hs);
111 
112 #endif
hashset_put
void hashset_put(t_hashset *hs, const void *val)
Adds a copy of the specified element to the hashset.
Definition: hashset_put.c:17
hashset_copy
t_hashset * hashset_copy(const t_hashset *hs)
Copies the hashset and all it contents.
Definition: hashset_copy.c:16
types.h
s_hashset::capacity
size_t capacity
The current capacity of the hashset.
Definition: hashset.h:47
hashset_new
t_hashset * hashset_new(const t_type *type)
Initializes a new empty set.
Definition: hashset_new.c:16
hashset_delete
void hashset_delete(t_hashset *hs)
Deletes this hashset and frees all its items and the associated data.
Definition: hashset_delete.c:16
utils.h
s_hashset::vals
void ** vals
The data.
Definition: hashset.h:45
hashset_contains
int hashset_contains(const t_hashset *hs, const void *val)
Is the specified element contained in the set?
Definition: hashset_contains.c:17
s_list
Doubly-linked list of generic items.
Definition: list.h:54
queue.h
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::size
size_t size
The number of elements in the hashset.
Definition: hashset.h:46
hashset_size
size_t hashset_size(const t_hashset *hs)
Returns the number of elements in this set.
Definition: hashset_size.c:16
hashset_vals
t_queue * hashset_vals(const t_hashset *hs)
Returns a queue with all the elements in the set.
Definition: hashset_vals.c:16
s_hashset
A dynamically resizing linear-probing hashset.
Definition: hashset.h:43
hashset_remove
void hashset_remove(t_hashset *hs, const void *val)
Removed the specified element from the set.
Definition: hashset_remove.c:32
s_hashset::type
const t_type * type
The type of elements in the hashset.
Definition: hashset.h:48