Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
iterator.c
Go to the documentation of this file.
1#include <stdlib.h>
2
3#include "iterator.h"
4
6 th_generic_table_t generic_table,
8 it->index = 0;
9 it->key = NULL;
10 it->current = NULL;
11 it->value = NULL;
12 it->generic_table = generic_table;
13 it->next = next;
14}
15
18 th_iterator_t *it = malloc(sizeof(th_iterator_t));
19
20 if (it == NULL) {
21 return NULL;
22 }
23
24 th_iterator_init(it, generic_table, next);
25
26 return it;
27}
28
30 th_iterator_init(it, NULL, NULL);
31
32 free(it);
33}
34
36 th_iterator_t *it = *ptr;
37
38 if (it->next == NULL) {
39 return false;
40 }
41
42 bool ret = it->next(ptr);
43
44 if (ret == false) {
46 }
47
48 return ret;
49}
bool th_iterator_next(th_iterator_t **ptr)
Try to get the next element. Free the iterator if it reachs the end.
Definition iterator.c:35
void th_iterator_free(th_iterator_t *it)
Free an iterator.
Definition iterator.c:29
static void th_iterator_init(th_iterator_t *it, th_generic_table_t generic_table, th_iterator_next_func_t next)
Definition iterator.c:5
th_iterator_t * th_iterator_create(th_generic_table_t generic_table, th_iterator_next_func_t next)
Allocate then init a new iterator.
Definition iterator.c:16
bool(* th_iterator_next_func_t)(th_iterator_t **)
Pointer on function that get the next element.
Definition iterator.h:24
Represents an iterator that allow to iterate over a generic table.
Definition iterator.h:11
th_any_t current
Definition iterator.h:13
th_any_t value
Definition iterator.h:15
th_generic_table_t generic_table
Definition iterator.h:16
bool(* next)(struct th_iterator_s **)
Definition iterator.h:17
th_key_t * key
Definition iterator.h:14
void * th_generic_table_t
Represents any table.
Definition types.h:14