-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtab_init.c
49 lines (41 loc) · 1.21 KB
/
htab_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*****************
** Vit Pavlik **
** xpavli0a **
** 251301 **
** **
** Created: **
** 2023-04-18 **
** **
** Last edited: **
** 2023-04-18 **
*****************/
// Fakulta: FIT VUT
// Vyvíjeno s gcc 10.2.1 na Debian GNU/Linux 11
#include "htab_priv.h"
#include <assert.h>
#include <stdio.h> // makra na vypisy chyb
#include <stdlib.h> // malloc free
htab_t *htab_init(const size_t n) {
assert(n > 0);
// alokace mista pro samotnou tabulku (struct) + malloc null check
htab_t *output = malloc(sizeof(htab_t));
malloc_null_check(output);
logv("MEM: alokace htab_t na %p", (void *)output);
// alokace pole ukazatelu na prvky tabulky + malloc null check
output->arr = malloc(n * sizeof(htab_ele_t *));
logv("MEM: alokace htab_t->arr (htab_ele_t**) na %p (%lu B)",
(void *)output->arr, n * sizeof(htab_ele_t *));
if (output->arr == NULL) {
free(output);
print_malloc_err();
return NULL;
}
// inicializace prvku tabulky na null
for (size_t i = 0; i < n; i++) {
output->arr[i] = NULL;
}
// inicializace metadat tabulky
output->size = 0;
output->arr_size = n;
return output;
}