|
|
1.1 ! root 1: /*ident "%W%" */ ! 2: /************************************************************************** ! 3: Copyright (c) 1984 AT&T ! 4: All Rights Reserved ! 5: ! 6: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T ! 7: ! 8: The copyright notice above does not evidence any ! 9: actual or intended publication of such source code. ! 10: ! 11: *****************************************************************************/ ! 12: #include <task.h> ! 13: #include "hw_stack.h" /* Needed for MAXINT_AS_FLOAT */ ! 14: ! 15: histogram::histogram(int nb, int ll, int rr) ! 16: { ! 17: register int i; ! 18: if (rr<=ll || nb<1) object::task_error(E_HISTO, (object*)0); ! 19: if (nb%2) nb++; ! 20: while ((rr-ll)%nb) rr++; ! 21: binsize = (rr-ll)/nb; ! 22: h = new int[nb]; ! 23: while (h == 0) object::task_error(E_STORE, (object*)0); ! 24: for (i=0; i<nb; i++) h[i] = 0; ! 25: l = ll; ! 26: r = rr; ! 27: nbin = nb; ! 28: sum = 0; ! 29: sqsum = 0; ! 30: } ! 31: ! 32: void ! 33: histogram::add(int a) ! 34: /* add a to one of the bins, adjusting histogram, if necessary */ ! 35: { ! 36: register int i, j; ! 37: ! 38: /* make l <= a < r, */ ! 39: /* possibly expanding histogram by doubling binsize and range */ ! 40: while (a<l) { ! 41: l -= r - l; ! 42: for (i=nbin-1, j=nbin-2; 0<=j; i--, j-=2) h[i] = h[j] + h[j+1]; ! 43: while(i >= 0) h[i--] = 0; ! 44: binsize += binsize; ! 45: } ! 46: while (r<=a) { ! 47: r += r - l; ! 48: for (i=0, j=0; i<nbin/2 ; i++, j+=2) h[i] = h[j] + h[j+1]; ! 49: while (i < nbin) h[i++] = 0; ! 50: binsize += binsize; ! 51: } ! 52: sum += a; ! 53: sqsum += a * a; ! 54: h[(a-l)/binsize]++; ! 55: } ! 56: ! 57: void ! 58: histogram::print() ! 59: /* ! 60: printout non-empty ranges ! 61: */ ! 62: { ! 63: register int i; ! 64: register int x; ! 65: int d = binsize; ! 66: ! 67: for (i=0; i<nbin; i++) { ! 68: if (x=h[i]) { ! 69: int ll = l+d*i; ! 70: printf("[%d:%d] : %d\n",ll,ll+d,x); ! 71: } ! 72: } ! 73: } ! 74: ! 75: float ! 76: randint::fdraw() ! 77: { ! 78: return ABS(DRAW)/(MAXINT_AS_FLOAT + 1); ! 79: } ! 80: ! 81: int ! 82: urand::draw() ! 83: { ! 84: return int(low + (high+1-low) * (0+randint::draw()/(MAXINT_AS_FLOAT+1))); ! 85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.