/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to tools/disp2.h

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Huge speed optimization posible:
 
2
        Replace corelation matrix on square of correlation matrix, it will
 
3
        remove need of cpu-consuming sqrt function
 
4
*/
 
5
#include <math.h>
 
6
 
 
7
 
 
8
struct _disp {
 
9
    unsigned long disp_n;
 
10
    unsigned long disp_s;
 
11
    double disp_d;
 
12
    double disp_m;
 
13
};
 
14
 
 
15
typedef struct _disp *disp;
 
16
 
 
17
disp disp_init() {
 
18
        disp d = (disp)malloc(sizeof(struct _disp));
 
19
        d->disp_n=0;
 
20
        d->disp_s=0;
 
21
        d->disp_d=0;
 
22
        return d;
 
23
}
 
24
 
 
25
void disp_deinit(disp d) {
 
26
    free(d);
 
27
}
 
28
 
 
29
void disp_event(disp d,unsigned long disp_v) {
 
30
        unsigned long t;
 
31
        
 
32
        d->disp_n++;
 
33
        t=d->disp_n*(d->disp_n-1);
 
34
        
 
35
        d->disp_s+=disp_v;
 
36
        disp_v*=d->disp_n;
 
37
 
 
38
        if (t) d->disp_d+=(double)(((d->disp_s-disp_v)*(d->disp_s-disp_v)))/t;
 
39
}
 
40
 
 
41
void disp_post(disp d) {
 
42
    if (d->disp_n>0) {
 
43
        d->disp_m = ((double)d->disp_s) / d->disp_n;
 
44
        if (d->disp_n>1) {
 
45
            d->disp_d /= (d->disp_n-1);
 
46
            d->disp_d = sqrt(d->disp_d);
 
47
        }
 
48
    }
 
49
}