-
Notifications
You must be signed in to change notification settings - Fork 4
/
Itemset.h
182 lines (153 loc) · 3.61 KB
/
Itemset.h
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
#ifndef __ITEMSET_H
#define __ITEMSET_H
#include <iostream>
#include <stdio.h>
#include <errno.h>
#include <vector>
#include "Array.h"
#include "Lists.h"
#include "spade.h"
//#include "Bitvec.h"
//#define SETBIT(a,b) ((a) |= (1 << (b)))
//#define UNSETBIT(a,b) ((a) &= ~(1 << (b)))
#define SETBIT(a,v,b) (((v) != 0) ? ((a) | (01 << (b))): ((a) & ~(01 << (b))))
#define GETBIT(a,b) ((a) & (01 << (b)))
extern int NUMCLASS;
class Itemset{
protected:
Array *theItemset;
Array *theIval;
vector<ullint> *theMcnt; //for multiple counts
ullint theSupport;
int *clsSup;
public:
Itemset(int it_sz, int ival_sz, int nclass = NUMCLASS);
~Itemset();
friend ostream& operator << (ostream& outputStream, Itemset& itemset);
void intersect_neighbors(Itemset *it1, Itemset *it2);
int compare(Itemset& ar2, int len);
int compare(Itemset& ar2);
int compare(Array& ar2, int len);
int compare(Itemset& ar2, int len, unsigned int);
int subsequence(Itemset * ar);
void print_seq(int itempl);
void print_idlist();
vector<ullint> *&mcnt()
{
return theMcnt;
}
ullint mcnt(int pos)
{
return (*theMcnt)[pos];
}
void increment_mcnt(){
//(*theMcnt)[theMcnt->size()-1] += 1;
theMcnt->back()++;
}
Array *&ival()
{
return theIval;
}
int ival(int pos)
{
return (*theIval)[pos];
}
int ivalsize()
{
return theIval->size();
}
void add_ival(int it)
{
theIval->add(it);
}
void reallocival()
{
theIval->realloc(ivalsize());
}
void add_ival(Array * ary)
{
for (int i=0; i < ary->size(); i++)
theIval->add((*ary)[i]);
}
int operator [] (int pos){
return (*theItemset)[pos];
};
int item(int pos){
return (*theItemset)[pos];
};
void setitem(int pos, int val){
theItemset->setitem(pos, val);
};
void set_itemset (Array *ary)
{
theItemset = ary;
}
Array * itemset(){
return theItemset;
};
void add_item(int val){
theItemset->add(val);
};
int size(){
return theItemset->size();
};
ullint support(){
return theSupport;
};
void set_support(ullint sup)
{
theSupport = sup;
}
void increment_support(){
theSupport++;
};
int cls_support(int cls){
return clsSup[cls];
}
void increment_cls_support(int cls){
clsSup[cls]++;
}
void set_cls_support(ullint sup, int cls)
{
clsSup[cls] = sup;
}
static int intcmp (void *it1, void *it2)
{
int i1 = *(int *) it1;
int i2 = *(int *) it2;
//printf("cmp %d %d\n", i1->theSupport,
if (i1 > i2) return 1;
else if (i1 < i2) return -1;
else return 0;
}
static int supportcmp (void *it1, void *it2)
{
Itemset * i1 = (Itemset *)it1;
Itemset * i2 = (Itemset *)it2;
//printf("cmp %d %d\n", i1->theSupport,
if (i1->theSupport > i2->theSupport) return 1;
else if (i1->theSupport < i2->theSupport) return -1;
else return 0;
}
static int Itemcompare(void * iset1, void *iset2)
{
Itemset *it1 = (Itemset *) iset1;
Itemset *it2 = (Itemset *) iset2;
return it1->compare(*it2);
}
//assume ts1 and ts2 are of same length
static int compare_seq(void *ts1, void *ts2, int len)
{
int *tseq1 = (int *)ts1;
int *tseq2 = (int *)ts2;
for (int i=0; i < len; i++){
if (tseq1[i] > tseq2[i]) return 1;
else if (tseq1[i] < tseq2[i]) return -1;
}
return 0;
}
//int find(int , int*);
//int subsequence(Itemset &);
//int compare(Itemset &);
};
#endif //__ITEMSET_H