-
Notifications
You must be signed in to change notification settings - Fork 0
/
campaign_generator.hpp
124 lines (109 loc) · 3.33 KB
/
campaign_generator.hpp
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
/******************************************************************************
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************
*/
/*
* Classes of the Yahoo! Streaming Benchmark (TBB FlowGraph version)
*
* This version of the Yahoo! Streaming Benchmark is the one modified in the
* StreamBench project available in GitHub:
* https://github.com/lsds/StreamBench
*/
#ifndef COMPAIGN_H
#define COMPAIGN_H
// include
#include <utility>
#include <iostream>
#include <unordered_map>
using namespace std;
// campaign_record struct
struct campaign_record
{
unsigned long ad_id;
unsigned long cmp_id;
// constructor
campaign_record() {}
// destructor
~campaign_record() {}
};
class CampaignGenerator {
private:
unsigned int adsPerCampaign;
unsigned long **arrays;
unordered_map<unsigned long, unsigned int> map;
campaign_record *relational_table;
public:
// constructor
CampaignGenerator(unsigned int _adsPerCampaign=10): adsPerCampaign(_adsPerCampaign)
{
// create the arrays
arrays = (unsigned long **) malloc(sizeof(unsigned long *) * N_CAMPAIGNS * adsPerCampaign);
for(size_t i=0; i<N_CAMPAIGNS*adsPerCampaign; i++)
arrays[i] = (unsigned long *) malloc(sizeof(unsigned long) * 2);
// create the relational table
relational_table = (campaign_record *) malloc(sizeof(campaign_record) * N_CAMPAIGNS * adsPerCampaign);
// initialize the arrays and the relational table
int value = 0;
int value2 = 0;
unsigned long ad_id, cmp_id;
for (size_t k=0; k<N_CAMPAIGNS; k++) {
cmp_id = (value2);
value2++;
for (size_t i=0; i<adsPerCampaign; i++) {
ad_id = value;
relational_table[(k*adsPerCampaign) + i].ad_id = ad_id;
relational_table[(k*adsPerCampaign) + i].cmp_id = cmp_id;
arrays[value][0] = 0;
arrays[value][1] = ad_id;
value++;
}
}
// initialize the hashmap
for (unsigned int k=0; k<(N_CAMPAIGNS * adsPerCampaign); k++) {
ad_id = relational_table[k].ad_id;
map.insert(pair<unsigned long, unsigned int>(ad_id, k));
}
}
// destructor
~CampaignGenerator()
{
// delete the arrays
for(size_t i=0; i<N_CAMPAIGNS*adsPerCampaign; i++)
delete arrays[i];
delete arrays;
// delete the relational table
delete relational_table;
}
// get number of ads per campaign
unsigned int getAdsCompaign() const
{
return adsPerCampaign;
}
// get a pointer to the relational table
campaign_record *getRelationalTable() const
{
return relational_table;
}
// get a pointer to the arrays
unsigned long **getArrays() const
{
return arrays;
}
// get a reference to the hashmap
unordered_map<unsigned long, unsigned int> &getHashMap()
{
return map;
}
};
#endif