/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_UTILITIES_NUMBERSEQ_HPP
#define SHARE_VM_UTILITIES_NUMBERSEQ_HPP
#include "memory/allocation.hpp"
/**
** This file contains a few classes that represent number sequence,
** x1, x2, x3, ..., xN, and can calculate their avg, max, and sd.
**
** Here's a quick description of the classes:
**
** AbsSeq: abstract superclass
** NumberSeq: the sequence is assumed to be very long and the
** maximum, avg, sd, davg, and dsd are calculated over all its elements
** TruncatedSeq: this class keeps track of the last L elements
** of the sequence and calculates avg, max, and sd only over them
**/
private:
protected:
// This is what we divide with to get the average. In a standard
// number sequence, this should just be the number of elements in it.
public:
virtual double maximum() const = 0; // maximum element in the sequence
virtual double last() const = 0; // last element added in the sequence
// the number of elements in the sequence
// the sum of the elements in the sequence
double avg() const; // the average of the sequence
double variance() const; // the variance of the sequence
double sd() const; // the standard deviation of the sequence
double davg() const; // decaying average
double dvariance() const; // decaying variance
double dsd() const; // decaying "standard deviation"
virtual void dump();
virtual void dump_on(outputStream* s);
};
private:
protected:
double _last;
public:
virtual void dump_on(outputStream* s);
};
private:
enum PrivateConstants {
};
void init();
protected:
public:
// accepts a value for L
double alpha = DEFAULT_ALPHA_VALUE);
~TruncatedSeq();
virtual double maximum() const;
virtual double last() const; // the last value added to the sequence
double oldest() const; // the oldest valid value in the sequence
double predict_next() const; // prediction based on linear regression
virtual void dump_on(outputStream* s);
};
#endif // SHARE_VM_UTILITIES_NUMBERSEQ_HPP