comparison Histogram.c @ 5:13b8591dd045

added addInterval -- is old version, have to merge with VMS__malloc version
author SeanHalle
date Thu, 11 Nov 2010 05:37:07 -0800
parents 6e864a0cb520
children a2388fae93ff
comparison
equal deleted inserted replaced
0:2a791e7d37a2 3:0cf30147687a
21 * accordingly. Use the bin-width to calculate the bin boundaries. 21 * accordingly. Use the bin-width to calculate the bin boundaries.
22 */ 22 */
23 23
24 24
25 Histogram * 25 Histogram *
26 makeHistogram( int numBins, int startOfRange, int endOfRange ) 26 makeHistogram( int32 numBins, int32 startOfRange, int32 endOfRange )
27 { 27 {
28 Histogram *hist; 28 Histogram *hist;
29 int i; 29 int32 i;
30 30
31 hist = malloc( sizeof(Histogram) ); 31 hist = malloc( sizeof(Histogram) );
32 hist->bins = malloc( numBins * sizeof(int) ); 32 hist->bins = malloc( numBins * sizeof(int32) );
33 33
34 hist->numBins = numBins; 34 hist->numBins = numBins;
35 hist->binWidth = (endOfRange - startOfRange) / numBins; 35 hist->binWidth = (endOfRange - startOfRange) / numBins;
36 hist->endOfRange = startOfRange + hist->binWidth * numBins; 36 hist->endOfRange = startOfRange + hist->binWidth * numBins;
37 hist->startOfRange = startOfRange; 37 hist->startOfRange = startOfRange;
42 } 42 }
43 43
44 return hist; 44 return hist;
45 } 45 }
46 46
47 void 47 void inline
48 addToHist( int value, Histogram *hist ) 48 addToHist( int32 value, Histogram *hist )
49 { 49 {
50 int binIdx; 50 int32 binIdx;
51 51
52 if( value < hist->startOfRange ) 52 if( value < hist->startOfRange )
53 { binIdx = 0; 53 { binIdx = 0;
54 } 54 }
55 else if( value > hist->endOfRange ) 55 else if( value > hist->endOfRange )
61 } 61 }
62 62
63 hist->bins[ binIdx ] += 1; 63 hist->bins[ binIdx ] += 1;
64 } 64 }
65 65
66
67 void inline
68 addIntervalToHist( int32 startIntvl, int32 endIntvl, Histogram *hist )
69 {
70 int32 value;
71
72 value = endIntvl - startIntvl;
73 if( value < 0 || value > 10000000 ) return; //sanity check
74 addToHist( value, hist );
75 }
76
66 void 77 void
67 printHist( Histogram *hist ) 78 printHist( Histogram *hist )
68 { 79 {
69 int binIdx, i, numBars, maxHeight, barValue, binStart, binEnd; 80 int32 binIdx, i, numBars, maxHeight, barValue, binStart, binEnd;
70 81
71 maxHeight = 0; 82 maxHeight = 0;
72 for( i = 0; i < hist->numBins; i++ ) 83 for( i = 0; i < hist->numBins; i++ )
73 { 84 {
74 if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; 85 if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ];