-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistribution.c
51 lines (37 loc) · 1.04 KB
/
distribution.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
50
51
/*******************************************************************************
* distribution handler of fraggy.agg
*
* @author Lars Thoms
* @date 2020-01-24
******************************************************************************/
#include "distribution.h"
struct distribution_tpl* distribution = NULL;
void increase_distribution(int key)
{
struct distribution_tpl *s;
HASH_FIND_INT(distribution, &key, s);
if(s == NULL)
{
s = (struct distribution_tpl*) malloc(sizeof * s);
s->key = key;
s->value = 0;
HASH_ADD_INT(distribution, key, s);
}
s->value++;
}
int sort_distribution(struct distribution_tpl *a, struct distribution_tpl *b)
{
return (a->key - b->key);
}
void print_distribution()
{
struct distribution_tpl *s;
// Sort by key
HASH_SORT(distribution, sort_distribution);
// Create CSV
fprintf(stdout, "fragments,amount\n");
for(s = distribution; s != NULL; s = s->hh.next)
{
fprintf(stdout, "%d,%d\n", s->key, s->value);
}
}