-
Notifications
You must be signed in to change notification settings - Fork 2
/
Itemset.h
148 lines (125 loc) · 3.03 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
#ifndef __ITEMSET_H
#define __ITEMSET_H
#include <iostream>
#include <stdio.h>
#include <errno.h>
#include "Array.h"
#include "Lists.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)))
class Itemset{
protected:
Array *theItemset;
Array *theIval;
int theSupport;
public:
Itemset(int it_sz, int ival_sz);
~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);
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]);
}
void print_seq(int itempl);
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();
};
int support(){
return theSupport;
};
void set_support(int sup)
{
theSupport = sup;
}
void increment_support(){
theSupport++;
};
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