1 // This may look like C code, but it is really -*- C++ -*-
3 Copyright (C) 1988 Free Software Foundation
4 written by Dirk Grunwald (grunwald@cs.uiuc.edu)
6 This file is part of the GNU C++ Library. This library is free
7 software; you can redistribute it and/or modify it under the terms of
8 the GNU Library General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version. This library is distributed in the hope
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #pragma implementation
23 #include "SGSmplhist.hxx"
31 #define HUGE_VAL DBL_MAX
35 const int SampleHistogramMinimum = -2;
36 const int SampleHistogramMaximum = -1;
38 SampleHistogram::SampleHistogram (double low, double high, double width)
49 width = (high - low) / 10;
52 howManyBuckets = int ((high - low) / width) + 2;
53 bucketCount = new int[howManyBuckets];
54 bucketLimit = new double[howManyBuckets];
56 for (int i = 0; i < howManyBuckets; i++)
62 bucketLimit[howManyBuckets - 1] = HUGE_VAL; /* from math.h */
65 SampleHistogram::~SampleHistogram ()
67 if (howManyBuckets > 0)
74 void SampleHistogram::operator += (double value)
77 for (i = 0; i < howManyBuckets; i++)
79 if (value < bucketLimit[i])
83 this->SampleStatistic::operator += (value);
86 int SampleHistogram::similarSamples (double d)
89 for (i = 0; i < howManyBuckets; i++)
91 if (d < bucketLimit[i])
92 return (bucketCount[i]);
97 void SampleHistogram::printBuckets (ostream & s)
99 for (int i = 0; i < howManyBuckets; i++)
101 if (bucketLimit[i] >= HUGE_VAL)
103 s << "< max : " << bucketCount[i] << "\n";
107 s << "< " << bucketLimit[i] << " : " << bucketCount[i] << "\n";
112 void SampleHistogram::reset ()
114 this->SampleStatistic::reset ();
115 if (howManyBuckets > 0)
117 for (register int i = 0; i < howManyBuckets; i++)