root/tags/5.4.pre05/ciiflh.c

Revision 1, 6.0 kB (checked in by heitor.barbieri, 4 years ago)

Criação do svn para Cisis.

Line 
1#if !CICPP
2static LONGX tlcpaddr;  /* info1 */
3#if MY
4static LONGX tlcppsts;  /* info2 */
5#endif
6static LONGX tlcpdocs;  /* info3 */
7static LONGX tlcinfo3;  /* info3 for ciifl.c */
8static UBYTE *areabits=NULL;
9static LONGX threshold;
10static LONGX tlcmxmfn;  /* current */
11static FILE *fplog = NULL;
12static char *iyp_buff=NULL;
13static unsigned int iyp_left;
14#define IYPBSIZ 8192L /* ou INT_MAX */
15#endif /* CICPP */
16
17/* prototypes */
18#if !CICPP
19#if ANSI
20LONGX tlputifp(char *areap, LONGX nbytes);
21void iyp_storinit(LONGX parmxmfn, char *parmlogp);
22void iyp_storlast(int storcond, char *storkeyp, int pstflag);
23void iyp_storthis(LONGX mfn,LONGX parmxmfn,
24                        char *keyp,LONGX count,int tag,int occ,int cnt);
25void iyp_storclos(void);
26#else
27LONGX tlputifp();
28void iyp_storinit();
29void iyp_storlast();
30void iyp_storthis();
31void iyp_storclos();
32#endif /* ANSI */
33#endif /* CICPP */
34
35#if !CICPP
36static UBYTE mask;
37static UBYTE *bp;
38static LONGX tlputby;
39static int tlcpcase;
40static LONGX tlcloop,tlcmfn;
41static UBYTE *tlcp,*tlcq,tlcqmfn[PMFNSIZ];
42static int tlcloop2;
43#define XFD 0
44#if XFD
45int xfd;
46#endif
47#endif /* CICPP */
48
49#if CICPP
50LONGX CIIFL :: tlputifp(char *areap,
51                       LONGX  nbytes)
52#else /*CICPP*/
53LONGX tlputifp(areap,nbytes)
54char *areap;
55LONGX nbytes;
56#endif /*CICPP*/
57{
58    char *p,*bufp;
59    LONGX towrite;
60    unsigned int n;
61    if (!areap) {
62        if (iyp_left == IYPBSIZ) return(0L);
63        bufp=iyp_buff+(IYPBSIZ-iyp_left);
64        memset(bufp,0x00,iyp_left);
65        ifpwrit(dbxp,iyp_buff,IYPBSIZ);
66        return(0L);
67    }
68
69#if XFD
70 if (CIWRITE(xfd,areap,(size_t)nbytes) !=  nbytes) fatal("write/xfd");
71#endif
72    for (p=areap, towrite=nbytes; towrite; ) {
73        if (towrite <= iyp_left) {
74            n=(unsigned int)towrite;
75            bufp=iyp_buff+(IYPBSIZ-iyp_left);
76            memcpy(bufp,p,n);
77            iyp_left-=n;
78            break;
79        }
80        bufp=iyp_buff+(IYPBSIZ-iyp_left);
81        memcpy(bufp,p,iyp_left);
82        ifpwrit(dbxp,iyp_buff,IYPBSIZ);
83        towrite-=iyp_left;
84        p+=iyp_left;
85        iyp_left=IYPBSIZ;
86    }
87    return(nbytes);
88}
89
90#if CICPP
91void CIIFL :: iyp_storinit(LONGX  parmxmfn,
92                           char *parmlogp)
93#else /*CICPP*/
94void iyp_storinit(parmxmfn,parmlogp)
95LONGX parmxmfn;
96char *parmlogp;
97#endif /*CICPP*/
98{
99#if XFD
100xfd=CREAT("xfd.iyp",PERMIS); if (xfd <= 0) fatal("xfd");
101#endif
102    threshold=parmxmfn/8+1;
103    tlcpaddr=0;
104#if TRACORE
105printf("%s: coreleft=%ld\n","areabits",CORELEFT());
106#endif
107#if CICPP
108    try {areabits=(UBYTE *)new char[threshold];}
109    catch (BAD_ALLOC) { areabits = (UBYTE *)ALLONULL; }
110#else /* CICPP */
111    areabits=(UBYTE *)ALLOC((ALLOPARM)threshold);
112#endif /* CICPP */
113    if (areabits == (UBYTE *)ALLONULL) fatal("ALLOC/areabits");
114#if TRACORE
115printf("%s: coreleft=%ld\n","areabits",CORELEFT());
116#endif
117#if CICPP
118    try {iyp_buff=(char *)new char [IYPBSIZ];}
119    catch (BAD_ALLOC) {iyp_buff = (char *)ALLONULL;}
120#else /* CICPP */
121    iyp_buff=(char *)ALLOC((ALLOPARM)IYPBSIZ);
122#endif /* CICPP */
123    if (iyp_buff == (char *)ALLONULL) fatal("ALLOC/iyp_buff");
124#if TRACORE
125printf("%s: coreleft=%ld\n","iyp_buff",CORELEFT());
126#endif
127    iyp_left=IYPBSIZ;
128    memset(areabits,0x00,threshold);
129    tlcpdocs=tlcmxmfn=0;
130    if (parmlogp) if ((fplog=fopen(parmlogp,"w")) == NULL) fatal(parmlogp);
131}
132#if CICPP
133void CIIFL :: iyp_storlast(int   storcond,
134                           char *storkeyp,
135                           int   pstflag)
136#else /*CICPP*/
137void iyp_storlast(storcond,storkeyp,pstflag)
138int storcond;
139char *storkeyp;
140int pstflag;
141#endif /*CICPP*/
142{
143    unsigned char *q;
144    if (storcond) {
145        if (tlcpdocs * PMFNSIZ >= threshold ) tlcpcase = BITSTRING;
146        else tlcpcase = MFNSTRING;
147        switch (tlcpcase) {
148        case BITSTRING:
149#define FIXSTRING 1
150#if FIXSTRING
151            tlcinfo3= -threshold;
152#else
153            tlcinfo3= -(tlcmxmfn/8+1);
154#endif
155            if (pstflag == IFUPDICT) { tlputby= -tlcinfo3; break; }
156            tlputby=tlputifp((char *)areabits,-tlcinfo3);
157            break;
158        case MFNSTRING:
159            tlcinfo3=0;
160            if (pstflag == IFUPDICT) { tlputby=tlcpdocs*PMFNSIZ; break; }
161            tlputby=0; tlcmfn=0;
162            for (tlcp=areabits, tlcloop=tlcmxmfn/8+1; tlcloop--; tlcp++) {
163                if (!*tlcp) { tlcmfn+=8; continue; }
164                for (tlcloop2=8; tlcloop2--; tlcmfn++)
165                    if (*tlcp & bitmask[tlcmfn&BY8RMASK]) {
166                        tlcq=tlcqmfn;
167                        q=(unsigned char *)&tlcmfn;
168                        *tlcq++ = q[M1];
169                        *tlcq++ = q[M2];
170                        *tlcq++ = q[M3];
171#if LIND4
172                        *tlcq++ = q[M4];
173#endif
174                        tlputby+=tlputifp((char *)tlcqmfn,(LONGX)PMFNSIZ);
175                    }
176            }
177            break;
178        default: fatal("tlcpcase");
179        }
180        /* call svd to store btree */
181        lifp_store_btree(storkeyp,tlcpaddr,tlcpdocs,treecase);
182        /* and initialize new posting list */
183        memset(areabits,0x00,threshold);
184        tlcpdocs=tlcmxmfn=0;
185        tlcpaddr+=tlputby;
186    }
187}
188
189#if CICPP
190void CIIFL ::iyp_storthis(LONGX  mfn,
191                          LONGX  parmxmfn,
192                          char *keyp,
193                          LONGX  count,
194                          int   tag,
195                          int   occ,
196                          int   cnt)
197#else /*CICPP*/
198void iyp_storthis(mfn,parmxmfn,keyp,count,tag,occ,cnt)
199LONGX mfn,parmxmfn;
200char *keyp;
201LONGX count;
202int tag,occ,cnt;
203#endif /*CICPP*/
204{
205    if (mfn < 1 || mfn > parmxmfn) {
206        fprintf(stderr,"key/post=%s/%ld mfn=%ld maxmfn=%ld",
207                keyp,count,mfn,parmxmfn);
208        fatal("ciifl/ciifll2/offset");
209    }
210    bp =  &areabits[ mfn / 8];
211    mask = bitmask [ mfn & BY8RMASK ];
212    if (*bp & mask) {
213        if (fplog)
214            fprintf(fplog,"duplicated posting|%8ld|%5d|%5d|%5d|%s\n",
215                    mfn,tag,occ,cnt,keyp);
216    }
217    else {
218        *bp |= mask;
219        tlcpdocs++; /* one more doc */
220    }
221#if 0
222printf("%8ld|%5d|%5d|%5d|%s %02x %02x %02x %02x %02x %02x \n",
223mfn,tag,occ,cnt,keyp,
224areabits[0],areabits[1],areabits[2],areabits[3],areabits[4],areabits[5]);
225#endif
226    if (mfn > tlcmxmfn) tlcmxmfn=mfn;
227}
228void iyp_storclos()
229{
230    if (iyp_buff) {
231        tlputifp((char *)NULL,0L);
232#if CICPP
233        delete[] iyp_buff;
234#else
235        FREE(iyp_buff);
236#endif /* CICPP */
237    }
238#if CICPP
239    if (areabits) delete[] areabits;
240#else
241    if (areabits) FREE(areabits);
242#endif /* CICPP */
243}
Note: See TracBrowser for help on using the browser.