-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.cpp
140 lines (131 loc) · 2.5 KB
/
print.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "print.h"
#include "prob.h"
#include <stdio.h>
#include <cmath>
void printbits( uint8_t n )
{
uint8_t precision = 8;
uint8_t mask = ( 1 << ( precision - 1 ) );
while( precision != 0 )
{
if( ( n & mask ) == 0 )
{
printf( "0" );
}
else
{
printf( "1" );
}
n <<= 1;
precision--;
}
}
void printbits( uint16_t n )
{
uint8_t precision = 16;
uint16_t mask = ( 1 << ( precision - 1 ) );
while( precision != 0 )
{
if( ( n & mask ) == 0 )
{
printf( "0" );
}
else
{
printf( "1" );
}
n <<= 1;
precision--;
}
}
void printbits( uint32_t n )
{
uint8_t precision = 32;
uint32_t mask = ( 1 << ( precision - 1 ) );
while( precision != 0 )
{
if( ( n & mask ) == 0 )
{
printf( "0" );
}
else
{
printf( "1" );
}
n <<= 1;
precision--;
}
}
void printbits( uint64_t n )
{
uint8_t precision = 64;
uint64_t mask = ( ( ( uint64_t ) 1 ) << ( precision - 1 ) );
while( precision != 0 )
{
if( ( n & mask ) == 0 )
{
printf( "0" );
}
else
{
printf( "1" );
}
n <<= 1;
precision--;
}
}
void printbits( Body & body )
{
Body::iterator begin = body.begin( );
Body::iterator middle;
Body::iterator end = body.end( );
for( middle = begin; middle != end; middle++ )
{
printbits( * middle );
}
}
void print( Prob & prob )
{
uint32_t size = prob.sum.size( );
printf( "\n" );
printf( "\nthe probability distribution on %u symbols", size );
printf( " given by" );
printf( "\n symbol probability bits of information" );
uint32_t symbol;
for( symbol = 0; symbol < size; symbol++ )
{
printf( "\n %u ", symbol );
printf( "%f ", ( float ) prob[ symbol ] / DENOMINATOR );
printf( "%f", prob.information( symbol ) );
}
printf( "\nhas %f bits of entropy", prob.entropy( ) );
printf( "\n" );
}
void print( Data & data )
{
printf( "\nthe data\n " );
Data::iterator begin = data.begin( );
Data::iterator middle;
Data::iterator end = data.end( );
for( middle = begin; middle != end; middle++ )
{
printf( "%i", * middle );
}
}
void print( Data & data,
Prob & prob )
{
print( data );
printf( "\ncontains %4.1f bits of information", prob.information( data ) );
}
void print( Coder & coder )
{
printf( "\n" );
printf( "\nthe encoding" );
printf( "\n head " );
printbits( coder.head );
printf( "\n body " );
printbits( coder.body );
printf( "\ncontains %u bits of information", coder.information( ) );
printf( "\n" );
}