-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewexttpose.cc
799 lines (720 loc) · 22.8 KB
/
newexttpose.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
#include <cerrno>
#include <iostream>
#include <fstream>
#include <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include "calcdb.h"
#include "Array.h"
using namespace std;
/* #define bzero(b,len) (memset((b), '\0', (len)), (void) 0) */
#define MEG (1024*1204)
struct timeval tp;
#define seconds(tm) gettimeofday(&tp,(struct timezone *)0);\
tm=tp.tv_sec+tp.tv_usec/1000000.0
char input[300]; //input file name
char output[300]; //output file name
char idxfn[300];
char inconfn[300];
char it2fn[300];
char seqfn[300];
double MINSUP_PER = 0.0;
int MINSUPPORT = 0;
int do_invert = 1;
int do_l2 = 1;
int use_seq = 1;
int write_only_fcnt = 1;
char use_newformat = 1;
int num_partitions = 1;
char no_minus_off = 0;
char use_diff = 0;
FILE *fout;
typedef unsigned char CHAR;
long AMEM = 32*MEG;
int DBASE_NUM_TRANS=0; //tot trans for assoc, num cust for sequences
int DBASE_MAXITEM=0; //number of items
float DBASE_AVG_TRANS_SZ=0; //avg trans size
float DBASE_AVG_CUST_SZ=0; //avg cust size for sequences
int DBASE_TOT_TRANS=0; //tot trans for sequences
double tpose_time, offt_time, l2time;
void parse_args(int argc, char **argv)
{
extern char * optarg;
int c;
if (argc < 2)
cout << "usage: assocFB -i<infile> -o<outfile>\n";
else{
//Dbase_Ctrl_Blk::binary_input = false;
while ((c=getopt(argc,argv,"bi:o:p:s:a:dvlfm:xz"))!=-1){
switch(c){
// case 'b':
// Dbase_Ctrl_Blk::binary_input = true;
// break;
// case 'z':
// Dbase_Ctrl_Blk::nooffset = true;
// break;
case 'i': //input files
sprintf(input,"%s",optarg);
break;
case 'o': //output file names
sprintf(output, "%s.tpose", optarg);
sprintf(idxfn, "%s.idx", optarg);
sprintf(it2fn, "%s.2it", optarg);
sprintf(seqfn, "%s.2seq", optarg);
sprintf(inconfn, "%s.conf",optarg);
break;
case 'p': //number of partitions for inverted dbase
num_partitions = atoi(optarg);
break;
case 's': //support value for L2
MINSUP_PER = atof(optarg);
break;
case 'a': //turn off 2-SEQ calclation
use_seq = 0;
write_only_fcnt = atoi(optarg);
break;
case 'd': //output diff lists, i.e. U - tidlist, only with assoc
use_diff = 1;
break;
case 'l': //turn off L2 calculation
do_l2 = 0;
break;
case 'v': //turn of dbase inversion
do_invert = 0;
break;
case 'f':
use_newformat = 0;
break;
case 'm':
AMEM = atoi(optarg)*MEG;
break;
case 'x':
no_minus_off = 1;
break;
}
}
}
if (use_seq){
write_only_fcnt = 0;
}
if (use_diff){
use_seq = 0;
num_partitions = 1;
cout << "SEQ TURNED OFF and PARTITIONS = 1\n";
}
}
int cmp2it(const void *a, const void *b)
{
int *ary = (int *)a;
int *bry = (int *)b;
if (ary[0] < bry[0]) return -1;
else if (ary[0] > bry[0]) return 1;
else{
if (ary[1] < bry[1]) return -1;
else if (ary[1] > bry[1]) return 1;
else return 0;
}
}
int intcmp(const void *a, const void *b)
{
int ary = *(int *)a;
int bry = *(int *)b;
if (ary < bry) return -1;
else if (ary > bry) return 1;
else return 0;
}
void sort_get_l2(int &l2cnt, int fd, ofstream &ofd, int *backidx, int *freqidx,
int numfreq, int *offsets, CHAR *cntary, char use_seq)
{
//write 2-itemsets counts to file
int i, j, k, fcnt;
int lit;
long sortflen;
int *sortary;
int itbuf[3];
sortflen = lseek(fd, 0, SEEK_CUR);
if (sortflen < 0){
perror("SEEK SEQ");
exit(errno);
}
//cout << "SORT " << sortflen << endl;
if (sortflen > 0){
#ifdef DEC
sortary = (int *) mmap((char *)NULL, sortflen,
(PROT_READ|PROT_WRITE),
(MAP_FILE|MAP_VARIABLE|MAP_PRIVATE), fd, 0);
#else
sortary = (int *) mmap((char *)NULL, sortflen,
(PROT_READ|PROT_WRITE),
MAP_PRIVATE, fd, 0);
#endif
if (sortary == (int *)-1){
perror("SEQFd MMAP ERROR");
exit(errno);
}
qsort(sortary, (sortflen/sizeof(int))/2, 2*sizeof(int), cmp2it);
}
int numel = sortflen/sizeof(int);
i = 0;
fcnt = 0;
for (j=0; j < numfreq;j++){
if (use_seq) k = 0;
else k = j+1;
for (; k < numfreq;k++){
fcnt = 0;
if (sortflen > 0 && i < numel){
while (i < numel &&
j == freqidx[sortary[i]] && k == freqidx[sortary[i+1]]){
fcnt += 256;
i += 2;
}
}
if (use_seq) fcnt += (int) cntary[j*numfreq+k];
else{
lit = j;
lit = (offsets[lit]-lit-1);
fcnt += (int) cntary[lit+k];
}
if (fcnt >= MINSUPPORT){
if (write_only_fcnt){
ofd.write((char *)&fcnt, ITSZ);
}
else{
itbuf[0] = backidx[j];
itbuf[1] = backidx[k];
itbuf[2] = fcnt;
ofd.write((char *)itbuf, 3*ITSZ);
}
//cout << backidx[j] << ((use_seq)?" -> ":" ")
// << backidx[k] << " SUPP " << fcnt << endl;
l2cnt++;
}
}
}
if (sortflen > 0) munmap((caddr_t)sortary, sortflen);
}
void process_cust(int *fidx, int fcnt, int numfreq, int *backidx,
Array **extary, CHAR *seq2, CHAR *itcnt2, char *ocust,
int *offsets, int seqfd, int isetfd)
{
int j, k, lit;
int ii1, ii2;
// qsort(fidx, fcnt, sizeof(int), intcmp);
// cout << "FIDX ";
// for (k=0; k < fcnt; k++)
// cout << " " << backidx[fidx[k]];
// cout << endl;
// for (k=0; k < fcnt; k++){
// cout << backidx[fidx[k]] << ": ";
// for (j=k+1; j < fcnt; j++){
// cout << " " << (int) ocust[offsets[fidx[k]]-fidx[k]-1+fidx[j]];
// }
// cout << endl;
// }
for (k=0; k < fcnt; k++){
for (j=k; j < fcnt; j++){
if (use_seq && extary[fidx[j]]->size()>0){
lit = extary[fidx[j]]->size()-1;
if ((*extary[fidx[k]])[0] < (*extary[fidx[j]])[lit]){
if ( (++seq2[fidx[k]*numfreq+fidx[j]]) == 0){
write(seqfd, (char *)&backidx[fidx[k]], ITSZ);
write(seqfd, (char *)&backidx[fidx[j]], ITSZ);
}
}
}
if (j > k){
if (fidx[k] < fidx[j]){
ii1 = fidx[k];
ii2 = fidx[j];
}
else{
ii2 = fidx[k];
ii1 = fidx[j];
}
lit = offsets[ii1]-ii1-1;
if (ocust[lit+ii2] == 1){
if ((++itcnt2[lit+ii2]) == 0){
write(isetfd, (char *)&backidx[ii1], ITSZ);
write(isetfd, (char *)&backidx[ii2], ITSZ);
//itcnt2[lit+ii2] = 0;
}
ocust[lit+ii2] = 0;
}
if (extary[fidx[k]]->size() > 0){
lit = extary[fidx[k]]->size()-1;
if ((*extary[fidx[j]])[0] < (*extary[fidx[k]])[lit]){
if ( (++seq2[fidx[j]*numfreq+fidx[k]]) == 0){
write(seqfd, (char *)&backidx[fidx[j]], ITSZ);
write(seqfd, (char *)&backidx[fidx[k]], ITSZ);
}
}
}
}
}
extary[fidx[k]]->reset();
}
}
void do_invert_db(Dbase_Ctrl_Blk *DCB, int pblk, Array **extary, int numfreq,
int *freqidx, int *backidx, int *fidx,
int mincustid, int maxcustid)
{
double t1, t2;
seconds(t1);
int numitem, tid, custid;
int *buf;
char tmpnam[300];
int i,j,k;
int fd;
int idx;
DCB->get_first_blk();
DCB->get_next_trans(buf, numitem, tid, custid);
int ocid;// = -1;
for (int p=0; p < num_partitions; p++){
if (num_partitions > 1) sprintf(tmpnam, "%s.P%d", output, p);
else sprintf(tmpnam, "%s", output);
if ((fd = open(tmpnam, (O_WRONLY|O_CREAT|O_TRUNC), 0666)) < 0){
perror("Can't open out file");
exit (errno);
}
for (i=0; i < numfreq; i++){
extary[i]->reset();
}
//count 2-itemsets
int plb = p*pblk + mincustid;
int pub = plb+pblk;
if (pub >= maxcustid) pub = maxcustid+1;
cout << "BOUNDS " << plb << " " << pub << endl;
int fcnt;
for (; !DCB->eof() && custid < pub;){
fcnt = 0;
ocid = custid;
//cout << "TID " << custid << " " << tid << " " << numitem << endl;
while (!DCB->eof() && ocid == custid && custid < pub){
//for (k=0; k < numitem; k++){
// }
if (use_diff){
//add this tid to all items not in the trans
k=0;
for (j=0; j < numitem; j++){
if (freqidx[buf[j]] == -1) continue;
while(backidx[k] < buf[j]){
//if ((idx = freqidx[backidx[k]]) != -1){
idx =k;
if (!use_newformat)
extary[idx]->add(fd, tid, use_seq, p);
else extary[idx]->add(fd, tid, use_seq, p, custid);
//}
k++;
}
k++; //skip over buf[j]
}
for (; k < numfreq; k++){
//if ((idx = freqidx[backidx[k]]) != -1){
idx = k;
if (!use_newformat)
extary[idx]->add(fd, tid, use_seq, p);
else extary[idx]->add(fd, tid, use_seq, p, custid);
//}
}
}
else{
// add this tid to all items in the trans
for (j=0; j < numitem; j++){
idx = freqidx[buf[j]];
if (idx != -1){
if (!use_newformat){
if (use_seq && extary[idx]->flg() == 0){
fidx[fcnt] = idx;
fcnt++;
extary[idx]->setflg(1);
extary[idx]->add(fd, tid, use_seq, p, custid);
}
else{
extary[idx]->add(fd, tid, use_seq, p);
}
}
else {
extary[idx]->add(fd, tid, use_seq, p, custid);
}
}
}
}
DCB->get_next_trans(buf, numitem, tid, custid);
}
if (!use_newformat && use_seq){
for (k=0; k < fcnt; k++){
extary[fidx[k]]->setlastpos();
extary[fidx[k]]->setflg(0);
}
fcnt = 0;
}
}
for (i=0; i < numfreq; i++){
//cout << "FLUSH " << i << " " << extary[i]->lastPos << " " <<
// extary[i]->theSize << endl;
extary[i]->flushbuf(fd,use_seq,p);
}
close(fd);
}
seconds(t2);
cout << "WROTE INVERT " << t2-t1 << endl;
tpose_time = t2-t1;
}
void tpose()
{
int i,j,l;
int idx;
int custid, tid, numitem, fcnt;
ofstream ofd;
double t1, t2;
int sumsup=0, sumdiff=0;
//read original Dbase config info
Dbase_Ctrl_Blk *DCB = new Dbase_Ctrl_Blk(input);
vector<int> itcnt(100);
vector<int> ocnt(100);
vector<int> itlen(100);
fill (itcnt.begin(), itcnt.end(), 0);
fill (itlen.begin(), itlen.end(), 0);
fill (ocnt.begin(), ocnt.end(), -1);
seconds(t1);
//count 1 items
int *buf;
DCB->get_first_blk();
DCB->get_next_trans(buf, numitem, tid, custid);
int mincustid = custid;
while (!DCB->eof()){
cout << custid << " " << tid << " " << numitem << endl;
for (j=0; j < numitem; j++){
//cout << " " << buf[j] << flush;
if (buf[j] >= itlen.size()){
itlen.resize(buf[j]+10,0);
itcnt.resize(buf[j]+10,0);
ocnt.resize(buf[j]+10,-1);
}
if (buf[i] > DBASE_MAXITEM) DBASE_MAXITEM = buf[i];
DBASE_NUM_TRANS++;
itlen[buf[j]]++;
if (use_seq && ocnt[buf[j]] != custid){
itcnt[buf[j]]++;
ocnt[buf[j]] = custid;
}
//if (buf[j] == 17) cout << " " << tid;
}
//cout << endl;
DCB->get_next_trans(buf, numitem, tid, custid);
}
//cout << endl;
int maxcustid = custid;
cout << "MINMAX " << mincustid << " " << maxcustid << endl;
DBASE_MAXITEM++;
MINSUPPORT = (int) (MINSUP_PER*DBASE_NUM_TRANS+0.5);
//ensure that support is at least 2
if (!write_only_fcnt && MINSUPPORT < 1) MINSUPPORT = 1;
cout << "MINSUPPORT " << MINSUPPORT << " " << DBASE_NUM_TRANS << endl;
//write config info to new file
int conffd;
if ((conffd = open(inconfn, (O_WRONLY|O_CREAT), 0666)) < 0){
perror("Can't open out file");
exit (errno);
}
if (!use_seq){
write(conffd,(char *)&DBASE_NUM_TRANS,ITSZ);
write(conffd,(char *)&DBASE_MAXITEM,ITSZ);
}
close(conffd);
int *freqidx = new int [DBASE_MAXITEM];
int numfreq=0;
for (i=0; i < DBASE_MAXITEM; i++){
if (use_seq){
if(itcnt[i] >= MINSUPPORT){
//cout << i << " SUPP " << itcnt[i] << endl;
freqidx[i] = numfreq;
numfreq++;
}
else freqidx[i] = -1;
}
else{
if(itlen[i] >= MINSUPPORT){
freqidx[i] = numfreq;
numfreq++;
sumsup += itlen[i];
sumdiff += (DBASE_NUM_TRANS - itlen[i]);
}
else freqidx[i] = -1;
}
//if (i == 17) cout << " 17 SUP " << itlen[17] << endl;
}
int *backidx = new int[numfreq];
numfreq=0;
for (i=0; i < DBASE_MAXITEM; i++){
if (use_seq){
if (itcnt[i] >= MINSUPPORT)
backidx[numfreq++] = i;
}
else{
if (itlen[i] >= MINSUPPORT)
backidx[numfreq++] = i;
}
}
seconds(t2);
cout << "numfreq " << numfreq << " : " << t2-t1
<< " SUMSUP SUMDIFF = " << sumsup << " " << sumdiff << endl;
fprintf(fout, " F1stats = [ %d %d %d %f ]", numfreq, sumsup, sumdiff, t2-t1);
if (numfreq == 0) return;
int extarysz = AMEM/numfreq;
extarysz /= sizeof(int);
cout << "EXTRARYSZ " << extarysz << endl;
if (extarysz < 2) extarysz = 2;
Array **extary = new Array *[numfreq];
for (i=0; i < numfreq; i++){
extary[i] = new Array(extarysz,num_partitions);
}
seconds(t1);
char tmpnam[300];
int plb, pub, pblk;
pblk = (int) ceil (((double)(maxcustid-mincustid+1))/num_partitions);
if (do_invert){
if (num_partitions > 1){
DCB->get_first_blk();
DCB->get_next_trans(buf, numitem, tid, custid);
}
for (j=0; j < num_partitions; j++){
//construct offsets for 1-itemsets
if (num_partitions > 1){
sprintf(tmpnam, "%s.P%d", idxfn, j);
plb = j*pblk + mincustid;
pub = plb+pblk;
if (pub > maxcustid) pub = maxcustid+1;
fill(itcnt.begin(), itcnt.end(), 0);
fill(ocnt.begin(), ocnt.end(), -1);
fill(itlen.begin(), itlen.end(), 0);
for (; !DCB->eof() && custid < pub; ){
for (i=0; i < numitem; i++){
itlen[buf[i]]++;
if (use_seq && ocnt[buf[i]] != custid){
itcnt[buf[i]]++;
ocnt[buf[i]] = custid;
}
}
DCB->get_next_trans(buf, numitem, tid, custid);
}
}
else sprintf(tmpnam, "%s", idxfn);
//cout << "100 VAL " << itcnt[100] << endl;
cout << "OPENED " << tmpnam << endl;
ofd.open(tmpnam);
if (!ofd){
perror("Can't open out file");
exit (errno);
}
int file_offset=0;
int null = -1;
for (i=0; i < DBASE_MAXITEM; i++){
//if (i == 17) cout << "LIDX " << i << " " << itlen[i] << endl;
if (freqidx[i] != -1){
ofd.write((char*)&file_offset, ITSZ);
extary[freqidx[i]]->set_offset(file_offset,j);
if (use_seq){
if (use_newformat) file_offset += (2*itlen[i]);
else file_offset += (2*itcnt[i]+itlen[i]);
}
else{
if (use_diff) file_offset += (DBASE_NUM_TRANS - itlen[i]);
else file_offset += itlen[i];
}
}
else if (no_minus_off){
ofd.write((char*)&file_offset, ITSZ);
}
else ofd.write((char*)&null, ITSZ);
//cout << "OFF " << i <<" " << file_offset << endl;
}
cout << "OFF " << i <<" " << file_offset << endl;
ofd.write((char *)&file_offset, ITSZ);
ofd.close();
}
}
seconds(t2);
cout << "Wrote Offt " << t2-t1 << endl;
offt_time = t2-t1;
int *fidx = new int[numfreq];
if (fidx == NULL){
perror("Can't alloc fidx");
exit (errno);
}
int ocid = -1;
if (do_l2){
seconds(t1);
int seqfd, isetfd;
if (use_seq){
if ((seqfd = open("tmpseq", (O_RDWR|O_CREAT|O_TRUNC), 0666)) < 0){
perror("Can't open out file");
exit (errno);
}
}
if ((isetfd = open("tmpiset", (O_RDWR|O_CREAT|O_TRUNC), 0666)) < 0){
perror("Can't open out file");
exit (errno);
}
CHAR *seq2;
if (use_seq){
seq2 = new CHAR [numfreq*numfreq];
if (seq2 == NULL){
perror("SEQ MMAP ERROR");
exit(errno);
}
//for (i=0; i < numfreq*numfreq; i++) seq2[i] = 0;
bzero((char *)seq2, numfreq*numfreq*sizeof(CHAR));
}
CHAR *itcnt2 = new CHAR [(numfreq*(numfreq-1)/2)];
if (itcnt2 == NULL){
perror("ITCNT MMAP ERROR");
exit(errno);
}
bzero((char *)itcnt2, (numfreq*(numfreq-1)/2)*sizeof(CHAR));
//for (i=0; i < numfreq*(numfreq-1)/2; i++) itcnt2[i] = 0;
char *ocust = new char [(numfreq*(numfreq-1)/2)];
if (ocust == NULL){
perror("OCUSt MMAP ERROR");
exit(errno);
}
bzero((char *)ocust, (numfreq*(numfreq-1)/2)*sizeof(char));
int *offsets = new int [numfreq];
int offt = 0;
for (i=numfreq-1; i >= 0; i--){
offsets[numfreq-i-1] = offt;
offt += i;
}
ocid = -1;
int lit;
//count 2-itemsets
DCB->get_first_blk();
DCB->get_next_trans(buf, numitem, tid, custid);
while(!DCB->eof()){
fcnt=0;
ocid = custid;
while(!DCB->eof() && ocid == custid){
for (j=0; j < numitem; j++){
idx = freqidx[buf[j]];
if (idx != -1){
if (use_seq){
if (extary[idx]->size() == 0){
fidx[fcnt] = idx;
fcnt++;
//extary[idx]->add(isetfd,tid,use_seq,0);
//extary[idx]->add(isetfd,tid,use_seq,0);
extary[idx]->setitem(0,tid);
extary[idx]->setitem(1,tid);
extary[idx]->setsize(2);
}
else{
extary[idx]->setitem(1,tid);
}
lit = offsets[idx]-idx-1;
for (l=j+1; l < numitem; l++){
if (freqidx[buf[l]] != -1){
ocust[lit+freqidx[buf[l]]] = 1;
}
}
}
else{
lit = offsets[idx]-idx-1;
for (l=j+1; l < numitem; l++){
if (freqidx[buf[l]] != -1){
if ((++itcnt2[lit+freqidx[buf[l]]]) == 0){
write(isetfd, (char *)&buf[j], ITSZ);
write(isetfd, (char *)&buf[l], ITSZ);
}
}
}
}
}
}
DCB->get_next_trans(buf, numitem, tid, custid);
}
if (use_seq){
process_cust(fidx, fcnt, numfreq, backidx, extary, seq2, itcnt2,
ocust, offsets, seqfd, isetfd);
}
}
delete [] ocust;
seconds(t2);
cout << "2-IT " << t2-t1 << " " << endl;
l2time = t2-t1;
seconds(t1);
//write 2-itemsets counts to file
int l2cnt = 0;
if (use_seq){
ofd.open(seqfn);
if (ofd.fail()){
perror("Can't open seq file");
exit (errno);
}
sort_get_l2(l2cnt, seqfd, ofd, backidx, freqidx,
numfreq, offsets, seq2, 1);
ofd.close();
cout << "SEQ2 cnt " << l2cnt << endl;
fprintf(fout, " %d", l2cnt);
}
int seqs = l2cnt;
ofd.open(it2fn);
//if ((fd = open(it2fn, (O_WRONLY|O_CREAT|O_TRUNC), 0666)) < 0){
if (ofd.fail()){
perror("Can't open it2 file");
exit (errno);
}
sort_get_l2(l2cnt, isetfd, ofd, backidx, freqidx,
numfreq, offsets, itcnt2, 0);
ofd.close();
seconds(t2);
cout << "SORT " << l2cnt << " " << t2-t1 << endl;
l2time += t2-t1;
fprintf(fout, " F2stats = [ %d %d %f ]", l2cnt, seqs, l2time);
if (use_seq) unlink("tmpseq");
unlink("tmpiset");
delete [] offsets;
delete [] itcnt2;
if (use_seq) delete [] seq2;
}
if (do_invert){
do_invert_db(DCB, pblk, extary, numfreq, freqidx, backidx, fidx, mincustid, maxcustid);
}
delete [] freqidx;
delete [] backidx;
//for (i=0; i < numfreq; i++)
// cout << "LAST " << backidx[i] << " "
// << extary[i]->get_offset() << endl;
delete DCB;
}
int main(int argc, char **argv)
{
double ts,te;
seconds(ts);
parse_args(argc, argv);
fout = fopen("summary.out", "a+");
if (fout == NULL){
perror("can't open summary");
exit(errno);
}
fprintf(fout, "TPOSE");
if (use_diff) fprintf (fout," DIFF");
if (use_seq) fprintf (fout," SEQ");
if (!do_invert) fprintf (fout," NOINVERT");
if (!do_l2) fprintf (fout," NOF2");
fprintf(fout, " %s %f %d %d %d", input, MINSUP_PER, DBASE_NUM_TRANS,
MINSUPPORT, num_partitions);
tpose();
seconds(te);
fprintf(fout, " %f %f %f\n", tpose_time, offt_time, te-ts);
fclose(fout);
cout << "Total elapsed time " << te-ts << endl;
exit(0);
}