-
Notifications
You must be signed in to change notification settings - Fork 0
/
storm.c
80 lines (60 loc) · 2.12 KB
/
storm.c
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
//ツリーのノードのクラス型
class Node {
string URL; //このノードのURL
unsigned int access; //このノードにアクセスした回数
Node *next[20] = {NULL}; //このノード次のURL 0:URL0へのポインタ, 1: ~
//コンストラクタ
Node(string url){
URL = url; //URL名を受け取る
access = 1;
}
//アクセススを増やす
void countUp(){
access++;
}
}
//各URLに応じて配列のインデックスをつける
enum {
URL0 = 0,
URL1,
//...
URL19
};
//各URLを始点とした場合の, Rootへのポインタ
Node *Root[20] = {NULL};
//Boltでの処理
void bolt1(TUPLE tuple){
int userID = tuple.value(0); //ユーザIDを取ってくる
string url = tuple.value(1); //アクセスしたURLを取ってくる
int urlNum = //enumからURLを配列番号に変換
Node *prev[20] = //DBからuserIDをつかって,(各URL機銃んと下)一つ前にアクセスしたノードへのポインタを取ってくる
//まだこのURLにアクセスした事が無い
if (prev[urlNum] == NULL){
if(Root[urlNum] == NULL) {
//そもそもこのURLにアクセスしたのがこいつが最初の場合
Root[urlNum] = prev[urlNum] = new Node(url);
}
else{
//Rootを取ってくる
Root[urlNum]->CountUp();
prev = Root[urlNum];
}
/* DBのuserIDの部分に 一つ前にアクセスしたノードを更新 */
}
for(int i=0;i<20;i++){
if(prev[i] == NULL) continue; //まだこのURLにアクセスした事が無いのは切る
if (prev[i]->next[urlNum] == NULL) { //この流れで,アクセスした人は過去にいない
if(Root[urlNum] == NULL){ //そもそもこのURLにアクセスしたのがこいつが最初の場合
Root[urlNum] = prev[i]->next[urlNum] = new Node(url);
}
else{
prev[i]->next[urlNum] = new Node(url);
}
}
else {
prev[i]->next[urlNum]->countUp(); //アクセス数を増やす
}
prev[i] = prev[i]->next[url];
/* DBのuserIDの部分に 一つ前にアクセスしたノードを更新 */
}
}