-
Notifications
You must be signed in to change notification settings - Fork 0
/
htab_statistics.c
43 lines (36 loc) · 973 Bytes
/
htab_statistics.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
// htab_statistics.c
// Řešení IJC-DU2, příklad 1), 18.4.2023
// Autor: Matyáš Oujezdský, FIT
// Přeloženo: clang version 10.0.0-4ubuntu1
#include <stdio.h>
#include "private_htab.h"
void htab_statistics(const htab_t *t) {
struct htab_item *tmp_ptr;
size_t item_count = 0;
double nonempty_count = 0;
size_t min = 0;
size_t max = 0;
double avg = 0;
for (size_t i = 0; i < t->arr_size; ++i) {
if (!t->arr_ptr[i]) {
continue;
}
tmp_ptr = t->arr_ptr[i];
++nonempty_count;
item_count = 0;
while (tmp_ptr) {
++item_count;
tmp_ptr = tmp_ptr->next;
}
if (max < item_count) {
max = item_count;
}
if (min > item_count || min == 0) {
min = item_count;
}
}
avg = t->size / nonempty_count;
printf("min: %zu\n", min);
printf("max: %zu\n", max);
printf("avg: %lf\n", avg);
}