-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemset.cc
136 lines (118 loc) · 3.1 KB
/
Itemset.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
#include <errno.h>
#include "Itemset.h"
Itemset::Itemset(int it_sz, int list_sz){
theItemset = new Array(it_sz);
if (theItemset == NULL){
perror("memory:: Itemset");
exit(errno);
}
theTidlist = new GArray<int>(list_sz);
if (theTidlist == NULL){
perror("memory:: Itemset");
exit(errno);
}
//theNeighbors = NULL;
theSubsets = NULL;
//if (it_sz > 2){
// theSubsets = new Itemset *[it_sz];
// if (theSubsets == NULL){
// perror("memory:: Itemset");
// exit(errno);
// }
//}
theSubsetcnt = 0;
theSupport = 0;
theDiff = 0;
theMaxflag = 0;
}
Itemset::~Itemset(){
if (theItemset) delete theItemset;
if (theTidlist) delete theTidlist;
if (theSubsets) {
delete [] theSubsets;
}
theItemset = NULL;
theTidlist = NULL;
theSubsets = NULL;
theDiff = 0;
theSupport = 0;
theMaxflag = 0;
}
ostream& operator << (ostream& outputStream, Itemset& itemset){
//outputStream << "ISET: ";
outputStream << *itemset.theItemset;
//outputStream << "SUP: ";
outputStream << "-1 ";
outputStream << itemset.theSupport;
//outputStream << " " << itemset.theDiff;
//itemset.theNeighbors->print();
//outputStream << " " << itemset.theNeighbors->size();
//outputStream << "the MAX:" << itemset.theMaxflag;
outputStream << "\n";
return outputStream;
}
// void Itemset::intersect_neighbors(Itemset *it1, Itemset *it2){
// theNeighbors->intersect(*it1->theNeighbors, *it2->theNeighbors);
// int bitset = theNeighbors->count_setbits();
// theNeighbors->set_size(bitset);
// };
int Itemset::compare(Itemset& ar2)
{
int len;
if (size() <= ar2.size()) len = size();
else len = ar2.size();
for(int i=0; i < len; i++){
if ((*theItemset)[i] > (*ar2.theItemset)[i]) return 1;
else if ((*theItemset)[i] < (*ar2.theItemset)[i]) return -1;
}
if (size() < ar2.size()) return -1;
else if (size() > ar2.size()) return 1;
else return 0;
}
//len must be less than length of both Itemsets
int Itemset::compare(Itemset& ar2, int len)
{
for(int i=0; i < len; i++){
if ((*theItemset)[i] > (*ar2.theItemset)[i]) return 1;
else if ((*theItemset)[i] < (*ar2.theItemset)[i]) return -1;
}
return 0;
}
int Itemset::compare(Array& ar2, int len)
{
for(int i=0; i < len; i++){
if ((*theItemset)[i] > ar2[i]) return 1;
else if ((*theItemset)[i] < ar2[i]) return -1;
}
return 0;
}
int Itemset::compare(Itemset& ar2, int len, unsigned int bvec)
{
int pos = 0;
int it;
for(int i=0; i < len; i++){
while (!GETBIT(bvec, pos)){
pos ++;
}
it = (*theItemset)[pos++];
if (it > (*ar2.theItemset)[i]) return 1;
else if (it < (*ar2.theItemset)[i]) return -1;
}
return 0;
}
int Itemset::subsequence(Itemset * ar)
{
int i,j;
if (size() > ar->size()) return 0;
int start = 0;
for(i=0; i < size(); i++){
for(j=start; j < ar->size(); j++){
if ((*theItemset)[i] == (*ar->theItemset)[j]){
start = j+1;
break;
}
}
if (j >= ar->size()) return 0;
}
return 1;
}