Skip to content

nullswan/c_hashtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c_hashtable

.github/workflows/norminette.yml
.github/workflows/tests.yml
Codacy Badge

theory

Fighint overlap theory

usage

#include "includes/hashtable.c"

int	main(void)
{
	t_hashtable	*hashtable;

	hashtable = hashtable_new(5);
	if (!hashtable)
		return (EXIT_FAILURE);
	hashtable_destroy(&hashtable, true);
	if (hashtable)
		return (EXIT_FAILURE);
	return (EXIT_SUCCESS);
}

required header

#include "includes/hashtable.c"

data types

# include <stdlib.h>
# include <stdbool.h>

typedef struct s_hashtable_item
{
	char		*key;
	void		*value;
}				t_hashtable_item;

typedef struct s_hashtable_bucket
{
	t_hashtable_item			*item;
	struct s_hashtable_bucket	*next;
}								t_hashtable_bucket;

typedef struct s_hashtable
{
	t_hashtable_item	**items;
	t_hashtable_bucket	**buckets;
	unsigned int		size;
	unsigned int		count;
}						t_hashtable;

item methods

t_hashtable_item	*hashtable_item_create(char *key, void *value);
void			hashtable_item_destroy(t_hashtable_item *item, bool dealloc_value);
t_hashtable_item	*hashtable_item_copy(t_hashtable **dst, t_hashtable_item *item);
void			*hashtable_item_get(t_hashtable *hashtable, char *key);
void				hashtable_item_remove( \
	t_hashtable *hashtable, t_hashtable_item *item);
t_hashtable_item	*hashtable_item_copy( \
	t_hashtable **dst, t_hashtable_item *item);

table method

t_hashtable_item	*hashtable_insert(t_hashtable **h, char *key, void *value);
t_hashtable		*hashtable_new(unsigned int size);
void			hashtable_destroy(t_hashtable **table, bool dealloc_value);
bool			hashtable_copy(t_hashtable **src, t_hashtable **dst);
void			hashtable_iter(t_hashtable *h, void (*f)(t_hashtable_item *));

About

C hashtable implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors