summaryrefslogtreecommitdiff
path: root/src/base/statistics.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/statistics.cc')
-rw-r--r--src/base/statistics.cc83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/base/statistics.cc b/src/base/statistics.cc
index 1e108298a..95402a221 100644
--- a/src/base/statistics.cc
+++ b/src/base/statistics.cc
@@ -236,6 +236,89 @@ Vector2dInfo::enable()
y_subnames.resize(y);
}
+void
+HistStor::grow_out()
+{
+ int size = cvec.size();
+ int zero = size / 2; // round down!
+ int top_half = zero + (size - zero + 1) / 2; // round up!
+ int bottom_half = (size - zero) / 2; // round down!
+
+ // grow down
+ int low_pair = zero - 1;
+ for (int i = zero - 1; i >= bottom_half; i--) {
+ cvec[i] = cvec[low_pair];
+ if (low_pair - 1 >= 0)
+ cvec[i] += cvec[low_pair - 1];
+ low_pair -= 2;
+ }
+ assert(low_pair == 0 || low_pair == -1 || low_pair == -2);
+
+ for (int i = bottom_half - 1; i >= 0; i--)
+ cvec[i] = Counter();
+
+ // grow up
+ int high_pair = zero;
+ for (int i = zero; i < top_half; i++) {
+ cvec[i] = cvec[high_pair];
+ if (high_pair + 1 < size)
+ cvec[i] += cvec[high_pair + 1];
+ high_pair += 2;
+ }
+ assert(high_pair == size || high_pair == size + 1);
+
+ for (int i = top_half; i < size; i++)
+ cvec[i] = Counter();
+
+ max_bucket *= 2;
+ min_bucket *= 2;
+ bucket_size *= 2;
+}
+
+void
+HistStor::grow_convert()
+{
+ int size = cvec.size();
+ int half = (size + 1) / 2; // round up!
+ //bool even = (size & 1) == 0;
+
+ int pair = size - 1;
+ for (int i = size - 1; i >= half; --i) {
+ cvec[i] = cvec[pair];
+ if (pair - 1 >= 0)
+ cvec[i] += cvec[pair - 1];
+ pair -= 2;
+ }
+
+ for (int i = half - 1; i >= 0; i--)
+ cvec[i] = Counter();
+
+ min_bucket = -max_bucket;// - (even ? bucket_size : 0);
+ bucket_size *= 2;
+}
+
+void
+HistStor::grow_up()
+{
+ int size = cvec.size();
+ int half = (size + 1) / 2; // round up!
+
+ int pair = 0;
+ for (int i = 0; i < half; i++) {
+ cvec[i] = cvec[pair];
+ if (pair + 1 < size)
+ cvec[i] += cvec[pair + 1];
+ pair += 2;
+ }
+ assert(pair == size || pair == size + 1);
+
+ for (int i = half; i < size; i++)
+ cvec[i] = Counter();
+
+ max_bucket *= 2;
+ bucket_size *= 2;
+}
+
Formula::Formula()
{
}