forked from gigablast/open-source-search-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataFeed.h
146 lines (124 loc) · 3.38 KB
/
DataFeed.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
// Gigablast, copyright Dec 2004
// Author: Javier Olivares
//
// . Contains Data Feed information for customers
// Has passcode and pricing table for this feed
#ifndef _DATAFEED_H_
#define _DATAFEED_H_
#include "MetaContainer.h"
//#include "Customer.h"
#include "CollectionRec.h" // for MAX_PRICE
#define DATAFEEDCOUNT_REQUESTS 1
#define DATAFEEDCOUNT_CURRENTBILL 2
#define MAX_USERNAMELEN 48
#define MAX_DATAFEEDPAGELEN (32*1024)
#define MAX_PASSCODELEN 8
#define MAX_PRICE_TIERS 6
#define MAX_PRICE_RESULTLEVELS 16
#define MAX_PRICE_LEVELCOSTS (MAX_PRICE_TIERS*MAX_PRICE_RESULTLEVELS*2)
class PriceTable {
public:
PriceTable() {
m_numTiers = 0;
m_numResultLevels = 0;
m_monthlyFee = 0;
}
~PriceTable() {
}
void reset ( ) {
m_numTiers = 0;
m_numResultLevels = 0;
m_monthlyFee = 0;
}
// . Get the cost of this query (in micro cents)
// given the total number of requests made for
// this feed this month and the number of results
// requested.
long getCost ( unsigned long totalRequests,
unsigned long numResults,
bool hasGigabits ) {
if (m_numTiers == 0 || m_numResultLevels == 0)
return 0;
// get the tier
long tier;
for (tier = 0; tier < m_numTiers-1; tier++)
if (totalRequests <= m_tierMax[tier])
break;
// get the level
long level;
for (level = 0; level < m_numResultLevels-1; level++)
if (numResults <= m_resultLevels[level])
break;
// return the cost
if (hasGigabits)
return m_levelCosts[ (tier * (m_numResultLevels*2))
+ (level*2+1) ];
else
return m_levelCosts[ (tier * (m_numResultLevels*2))
+ (level*2) ];
}
long getIndex ( unsigned long numResults,
bool hasGigabits ) {
// Check if we have result levels
if (m_numResultLevels == 0) return 0;
// Find the result level the query meets
long i;
for(i = 0; i < m_numResultLevels-1; i++)
if(numResults <= m_resultLevels[i])
break;
// Calculate any other changes to index
long opt = 0;
if(hasGigabits) opt |= 1;
// Return the proper Countdb index
return (m_resultLevels[i]/10 | opt);
}
/*
// clone the price table
void clone ( PriceTable *pt ) {
m_numTiers = pt->m_numTiers;
m_numResultLevels = pt->m_numResultLevels;
m_monthlyFee = pt->m_monthlyFee;
memcpy(m_tierMax, pt->m_tierMax, sizeof(long)*m_numTiers);
memcpy(m_resultLevels, pt->m_resultLevels, sizeof(long)*m_numResultLevels);
long numCosts = m_numTiers*m_numResultLevels*2;
memcpy(m_levelCosts, pt->m_levelCosts, sizeof(long)*numCosts);
}
*/
// locals
long m_numTiers;
unsigned long m_tierMax[MAX_PRICE_TIERS];
long m_numResultLevels;
unsigned long m_resultLevels[MAX_PRICE_RESULTLEVELS];
unsigned long m_levelCosts[MAX_PRICE_LEVELCOSTS];
long m_monthlyFee;
};
class DataFeed : public MetaContainer {
public:
DataFeed();
~DataFeed();
void setUrl ( char *name,
long nameLen );
void set ( long creationTime,
char *dataFeedUrl,
long dataFeedUrlLen,
char *passcode,
long passcodeLen,
bool isActive,
bool isLocked = false );
void parse ( char *dataFeedPage,
long dataFeedPageLen );
long buildPage ( char *page );
void buildPage ( SafeBuf *sb );
// locals
char m_passcode[MAX_PASSCODELEN+1];
long m_passcodeLen;
bool m_isActive;
bool m_isLocked;
// ID
long long m_customerId;
// Price Table
PriceTable m_priceTable;
// creation time
long m_creationTime;
};
#endif