Added tracking for percentiler modification; nixed some unneeded casts.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@424 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-09-11 00:36:35 +00:00
parent 15dd17a308
commit c08cad2642
@@ -57,7 +57,7 @@ public class Percentiler
iin.get(_counts); iin.get(_counts);
in.position((BUCKET_COUNT+1) * INT_SIZE); in.position((BUCKET_COUNT+1) * INT_SIZE);
LongBuffer lin = in.asLongBuffer(); LongBuffer lin = in.asLongBuffer();
_total = lin.get(); _snapTotal = (_total = lin.get());
// compute our percentiles // compute our percentiles
recomputePercentiles(); recomputePercentiles();
@@ -112,7 +112,7 @@ public class Percentiler
// of this bucket's counts to the two new buckets into // of this bucket's counts to the two new buckets into
// which it falls // which it falls
float fraction = (nval - (oval - delta)) / delta; float fraction = (nval - (oval - delta)) / delta;
int lesser = (int)Math.round(_counts[ii] * fraction); int lesser = Math.round(_counts[ii] * fraction);
counts[ni] += lesser; counts[ni] += lesser;
counts[++ni] += (_counts[ii] - lesser); counts[++ni] += (_counts[ii] - lesser);
nval += newdelta; nval += newdelta;
@@ -141,6 +141,23 @@ public class Percentiler
} }
} }
/**
* Returns true if thsi percentiler has been modified since it was created or since the last
* call to {@link #clearModified}.
*/
public boolean isModified ()
{
return (_total != _snapTotal);
}
/**
* Clears this percentiler's "is modified" state.
*/
public void clearModified ()
{
_snapTotal = _total;
}
/** /**
* Returns the percent of all numbers seen that are lower than the * Returns the percent of all numbers seen that are lower than the
* specified value. This value can range from zero to 100 (100 in the * specified value. This value can range from zero to 100 (100 in the
@@ -312,7 +329,7 @@ public class Percentiler
*/ */
protected final int toBucketIndex (float value) protected final int toBucketIndex (float value)
{ {
int idx = Math.min((int)Math.round(value * BUCKET_COUNT / _max), 99); int idx = Math.min(Math.round(value * BUCKET_COUNT / _max), 99);
if (idx < 0 || idx >= BUCKET_COUNT) { if (idx < 0 || idx >= BUCKET_COUNT) {
Log.warning("'" + value + "' caused bogus bucket index (" + Log.warning("'" + value + "' caused bogus bucket index (" +
idx + ") to be computed."); idx + ") to be computed.");
@@ -325,6 +342,9 @@ public class Percentiler
/** The total number of data points seen by this percentiler. */ /** The total number of data points seen by this percentiler. */
protected long _total; protected long _total;
/** The value of {@link #_total} at creation time or as of a call to {@link #clearModified}. */
protected long _snapTotal;
/** The maximum value seen by this percentiler. */ /** The maximum value seen by this percentiler. */
protected int _max; protected int _max;