-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.cpp
executable file
·106 lines (73 loc) · 1.81 KB
/
global.cpp
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
/*
* global.cpp
*
* Created on: Apr 1, 2009
* Author: luo
*/
#include "global.h"
#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;
const int MAX_THREAD = 1;
const int MAX_URL = 1000;
const int NUM_URL2FILE = 900;
const int NUM_URL2MEMERY = 100;
const int MAX_BUFFER = 512* 1024 - 1 ;
const int MAX_BUFFERPlus1 = MAX_BUFFER + 1;
const int MAX_HEAD = 512 - 1;
const int MAX_HEADPlus1 = MAX_HEAD + 1;
const int MAX_DOC = 800;
const int HASH_SEED = 1;
const int MAX_LRU = 150;
bool debug = false;
const char* amp="&";
int pagecounter = 0;
pthread_mutex_t mutex_counter;
//线程分配锁
pthread_mutex_t mutex_assign_thread;
int assignmode = 0, assign_counter = 0;
std::string integer2string(const int n) {
// std::stringstream newstr(std::stringstream::in | std::stringstream::out);
std::stringstream newstr;
if (!(newstr << n)) {
return "";
}
return newstr.str();
}
char* newStrChangeC(const char*p, char from, char to, int n) {
using namespace std;
int i;
const char* tmp;
char* result = new char[n];
memset(result, 0, n);
for (tmp = p, i = 0; (*tmp) && i < n; tmp++, i++) {
if (*tmp == from)
result[i] = to;
else
result[i] = *tmp;
}
return result;
}
/********************************************
功能:把字符串转换为全小写
********************************************/
void ToLowerCase(char * str) {
int i;
i = 0;
while (str[i] != '\0') {
str[i] = tolower(str[i]);
i++;
}
}
int bughunterc = 0;
int bughunterf = 0;
RabinHashFunction64 rabin_global(HASH_SEED);
//这个函数和urlseen 的long long hashurl(struct page_link*);等效
long long hash_site(struct page_link* ppl) {
long long v, v1, v2;
v1 = rabin_global.hash(ppl->_host_addr, 256);
v2 = rabin_global.hash(ppl->_host_file, 1024);
v = (v1 << 32) + v2;
return v;
}