-
Notifications
You must be signed in to change notification settings - Fork 2
/
distrib.c
63 lines (47 loc) · 1.34 KB
/
distrib.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
52
53
54
55
56
57
58
59
60
61
62
63
/* DISTRIB.C - Procedures for handling distributions over numbers. */
/* Based on Code by Radford M. Neal, see LICENSE_LDPC. */
#include "distrib.h"
/* The distrib type represents the distribution list. It stores a pointer to
an array of distrib_entry elements along with the length of this array.
Each distrib_entry contains a (number,proportion) pair.
The code by Neal supported defining more complicated distributions
(see http://radfordneal.github.io/LDPC-codes/pchk.html#make-ldpc).
However, I removed that feature and only support a single column weight.
Note that the actual column wight in the matrix can still vary due to 4cycle
removal.
*/
distrib *distrib_create
( int column_weight
)
{
distrib *d = chk_alloc(1, sizeof *d);
d->size = 1;
d->list = chk_alloc (1, sizeof(distrib_entry));
d->list[0].prop = 1;
d->list[0].num = column_weight;
return d;
}
/* FREE SPACE OCCUPIED A DISTRIBUTION LIST. */
void distrib_free
( distrib *d /* List to free */
)
{ free(d->list);
free(d);
}
/* RETURN THE MAXIMUM NUMBER IN A DISTRIBUTION LIST. Returns 0 if the list
pointer is 0. */
int distrib_max
( distrib *d /* List to examine */
)
{
int i;
int cur;
if (d==0) return 0;
cur = 0;
for (i = 1; i<d->size; i++)
{ if (d->list[i].num > d->list[cur].num)
{ cur = i;
}
}
return d->list[cur].num;
}