data_structures
Data Structures | Macros | Typedefs | Functions
hashset.h File Reference
#include <errno.h>
#include <sys/types.h>
#include "types.h"
#include "queue.h"
#include "utils.h"
+ Include dependency graph for hashset.h:

Go to the source code of this file.

Data Structures

struct  s_hashset
 A dynamically resizing linear-probing hashset. More...
 

Macros

#define HASHSET_INIT_CAPACITY   51
 The default initial capacity of a newly initialized hashset. More...
 

Typedefs

typedef struct s_hashset t_hashset
 

Functions

t_hashsethashset_new (const t_type *type)
 Initializes a new empty set. More...
 
void hashset_put (t_hashset *hs, const void *val)
 Adds a copy of the specified element to the hashset. More...
 
t_queuehashset_vals (const t_hashset *hs)
 Returns a queue with all the elements in the set. More...
 
size_t hashset_size (const t_hashset *hs)
 Returns the number of elements in this set. More...
 
void hashset_delete (t_hashset *hs)
 Deletes this hashset and frees all its items and the associated data. More...
 
int hashset_contains (const t_hashset *hs, const void *val)
 Is the specified element contained in the set? More...
 
void hashset_remove (t_hashset *hs, const void *val)
 Removed the specified element from the set. More...
 
t_hashsethashset_copy (const t_hashset *hs)
 Copies the hashset and all it contents. More...
 

Macro Definition Documentation

◆ HASHSET_INIT_CAPACITY

#define HASHSET_INIT_CAPACITY   51

The default initial capacity of a newly initialized hashset.

Definition at line 28 of file hashset.h.

Function Documentation

◆ hashset_contains()

int hashset_contains ( const t_hashset hs,
const void *  val 
)

Is the specified element contained in the set?

Parameters
valThe value
Returns
1 if the element is in the set, 0 otherwise

Definition at line 17 of file hashset_contains.c.

◆ hashset_copy()

t_hashset* hashset_copy ( const t_hashset hs)

Copies the hashset and all it contents.

Returns
The copy of the set

Definition at line 16 of file hashset_copy.c.

◆ hashset_delete()

void hashset_delete ( t_hashset hs)

Deletes this hashset and frees all its items and the associated data.

Does nothing if the argument is NULL.

Definition at line 16 of file hashset_delete.c.

◆ hashset_new()

t_hashset* hashset_new ( const t_type type)

Initializes a new empty set.

Parameters
typeThe type of items that this set can hold
Returns
The new hashset
Note
For this function to work, the type must be hashable (i.e. implement the hash function).

Definition at line 16 of file hashset_new.c.

◆ hashset_put()

void hashset_put ( t_hashset hs,
const void *  val 
)

Adds a copy of the specified element to the hashset.

Parameters
valThe value

Definition at line 17 of file hashset_put.c.

◆ hashset_remove()

void hashset_remove ( t_hashset hs,
const void *  val 
)

Removed the specified element from the set.

Parameters
valThe value
Returns
1 on success, 0 if the element is not in the set.

Definition at line 32 of file hashset_remove.c.

◆ hashset_size()

size_t hashset_size ( const t_hashset hs)

Returns the number of elements in this set.

Returns
The number of elements in this set.

Definition at line 16 of file hashset_size.c.

◆ hashset_vals()

t_queue* hashset_vals ( const t_hashset hs)

Returns a queue with all the elements in the set.

Returns
A queue with all the elements in the set.

Definition at line 16 of file hashset_vals.c.