https://github.com/nullswan/c_hashtable
C hashtable implementation
https://github.com/nullswan/c_hashtable
Last synced: over 1 year ago
JSON representation
C hashtable implementation
- Host: GitHub
- URL: https://github.com/nullswan/c_hashtable
- Owner: nullswan
- Created: 2021-07-16T22:25:30.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-21T16:46:10.000Z (almost 5 years ago)
- Last Synced: 2025-01-09T08:48:45.846Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 284 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# c_hashtable
[](https://github.com/c3b5aw/c_hashtable/actions/workflows/norminette.yml)
[](https://github.com/c3b5aw/c_hashtable/actions/workflows/tests.yml)
[](https://www.codacy.com/gh/c3b5aw/c_hashtable/dashboard?utm_source=github.com&utm_medium=referral&utm_content=c3b5aw/c_hashtable&utm_campaign=Badge_Grade)
## theory

### usage
```C
#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
```C
#include "includes/hashtable.c"
```
### data types
```C
# include
# include
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
```C
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
```C
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 *));
```