root/trunk/w2top.c

Revision 389, 4.8 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/* ==----------------------------- w2top.c -----------------------------== */
2
3int w2topjd (int cmd, WTFUN_ARRAY *awtfp, int coll, LONGX *xFREQ, float *xPESO, int howmany, float minweight)
4{
5        WTFUN_XWT *xwtp;//=awtfp->vwtfp[coll];
6
7        //int parmtrace=cmd;
8        int parmtrace2=(cmd >= 3)? cmd : 0;
9        LONGX docmfn=cmd;
10
11        LISTJD *hdr,*tail,*avail,*l;
12        LISTJD *prev;
13        float nextw;
14
15        float soma2;
16        //float invsqrts2;
17        float weight,termweight;
18
19        LONGX hidx;
20        LONGX *xfreqp;
21        int jocc;
22        LONGX loop;
23
24
25        //WTFUN_XWT current
26        xwtp=awtfp->vwtfp[coll];
27
28
29        /* setup list of relevant terms
30        */
31        memset(listjd,0x00,howmany*sizeof(LISTJD));
32        for (l=listjd, avail=listjd+1, loop=0; (LONGX)loop<(howmany-1); loop++, l++, avail++) l->avail=avail;
33        hdr=tail=avail=listjd;
34        listjdhdr=NULL;
35
36        soma2=0;
37        for (xfreqp=xFREQ, hidx=0, jocc=0, loop=jdmaxprim; loop--; xfreqp++, hidx++) {
38
39            /* select */
40            if (!*xfreqp) continue;
41            weight=xPESO[hidx];
42            /* optimize processing */
43            if (weight < minweight) continue;
44            jocc++; soma2+=weight*weight;
45            if (parmtrace2) {
46                char *jdhp=jdtable+(hidx*jdhwidth);
47                fprintf(stderr,"jdtop %d? %"_LD_" %f %"_LD_":%s\n",jocc,*xfreqp,weight,hidx,jdhp);
48            }
49
50            /* store in ordered list */
51                termweight = weight; /* * invsqrts2 */
52                prev=NULL;
53                l=NULL; if (hdr->weight) l=hdr;
54                while (l) {
55                    if (termweight < l->weight) { prev=l; l=l->next; }
56                    else break;
57                }
58                nextw=((l)?l->weight:0.0);
59                if (avail) {
60                        LISTJD *nextavail=avail->avail;
61                        avail->weight=termweight; avail->freq= *xfreqp; avail->hidx=hidx;
62                        avail->prev=prev;
63                        avail->next=l;
64                        if (prev) prev->next=avail;
65                        if (nextw) l->prev=avail;
66                        if (!avail->prev) hdr=avail;
67                        if (!avail->next) tail=avail;
68                        avail=nextavail;
69                        if (parmtrace2) fprintf(stderr,"top64a|");
70                }
71                else {
72                    if (termweight > tail->weight) {
73                        LISTJD *last=tail;
74                        LISTJD *repl=last;
75                        LISTJD *lnext=NULL;
76                        if (l) lnext=l->next;
77                        if (last->prev) {
78                            tail=last->prev;
79                            tail->next=NULL;
80                        }
81                        repl->weight=termweight; repl->freq= *xfreqp; repl->hidx=hidx;
82                        repl->prev=prev;
83                        if (prev) prev->next=repl;
84                        if (l) if (lnext) {
85                            repl->next=l;
86                            l->prev=repl;
87                        }
88                        if (!repl->prev) hdr=repl;
89                        if (!repl->next) tail=repl;
90                        if (parmtrace2) fprintf(stderr,"top64b|");
91                    }
92                }
93                if (parmtrace2) {
94                  char *jdhp=jdtable+(hidx*jdhwidth);
95                  fprintf(stderr,"%"_LD_"|%"_LD_":%s|%f\n",docmfn,hidx,jdhp,termweight);
96                  for (l=hdr; l; l=l->next) {
97                    char *jdhp;
98                    if (!l) break;
99                    jdhp=jdtable+(l->hidx*jdhwidth);
100                    fprintf(stderr,"%"_LD_"|%"_LD_":%s|%f p=%"_LD_"|n=%"_LD_"|a=%"_LD_" hdr=%"_LD_"|lst=%"_LD_"|prev=%"_LD_"\n",docmfn,l->hidx,jdhp,l->weight,
101                      (l->prev)?((LISTJD *)(l->prev))->hidx:-1,
102                      (l->next)?((LISTJD *)(l->next))->hidx:-1,
103                      (l->avail)?((LISTJD *)(l->avail))->hidx:-1,
104                      (hdr->hidx)?hdr->hidx:-1,
105                      (tail->hidx)?tail->hidx:-1,
106                      (prev)?prev->hidx:-1);
107                  }
108                  fprintf(stderr,"\n");
109                }
110
111            /* store in ordered list */
112        }
113       
114        listjdhdr=hdr;
115
116        /* skip empty vectors */
117        if (!soma2) {
118            return 0;
119        }
120
121#if NORMALIZE
122        /* calculate normalization factor = sqrt of sum of squares
123        */
124            if (soma2) invsqrts2=1/sqrt(soma2);
125
126        /* calculate final weight = local x global x normalization...
127        */
128        if (normalize)
129            if (normalize) {
130                LISTJD *l;
131            } /* end */
132        }
133#endif
134
135        /* doc done
136        */
137        //ffprintf(stderr,stderr,"++ %"_LD_"+%"_LD_"\n",zcount,zcount2);
138
139        return jocc;
140
141} /* end of topjd */
Note: See TracBrowser for help on using the browser.