From c08cad2642e1cb9e6968aa15f81082791e4052d5 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 11 Sep 2007 00:36:35 +0000 Subject: [PATCH] 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 --- .../parlor/rating/util/Percentiler.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/parlor/rating/util/Percentiler.java b/src/java/com/threerings/parlor/rating/util/Percentiler.java index 5f3fd2e0..969bfcec 100644 --- a/src/java/com/threerings/parlor/rating/util/Percentiler.java +++ b/src/java/com/threerings/parlor/rating/util/Percentiler.java @@ -57,7 +57,7 @@ public class Percentiler iin.get(_counts); in.position((BUCKET_COUNT+1) * INT_SIZE); LongBuffer lin = in.asLongBuffer(); - _total = lin.get(); + _snapTotal = (_total = lin.get()); // compute our percentiles recomputePercentiles(); @@ -112,7 +112,7 @@ public class Percentiler // of this bucket's counts to the two new buckets into // which it falls 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] += (_counts[ii] - lesser); 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 * 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) { - 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) { Log.warning("'" + value + "' caused bogus bucket index (" + idx + ") to be computed."); @@ -325,6 +342,9 @@ public class Percentiler /** The total number of data points seen by this percentiler. */ 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. */ protected int _max;