forked from gigablast/open-source-search-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cachedb.h
123 lines (101 loc) · 2.79 KB
/
Cachedb.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
// Matt Wells Copyright April 2013
// Cachedb - a semi-permanent cache for storing seo safebufs
// . so if they click on a different insertable term we can quickly
// send them the wordposinfos with WordPosInfo::m_trafficGain set.
// . Format of a 12-byte key in cachedb
// .
// . HHHHHHHH HHHHHHHH HHHHHHHH HHHHHHHH H = hash of the url
// . cccccccc cccccccc cccccccc cccccccc c = hash of the content
// . tttttttt 00000000 00000000 00000000 t = type of object
#ifndef _CACHEDB_H_
#define _CACHEDB_H_
// 12 byte key size
#define CACHEDBKS sizeof(key96_t)
#include "Rdb.h"
//#include "DiskPageCache.h"
// do not change these numbers, they are permanent and stored in cachedb
// that way... just add new numbers to the end.
enum {
cr_MatchingQueries = 0,
cr_RelatedDocIds = 1,
cr_RelatedQueries = 2,
cr_ScoredInsertableTerms = 3,
cr_WordPosInfoBuf = 4,
cr_Msg25SiteInfo = 5,
cr_Msg25PageInfo = 6,
cr_RecommendedLinks = 7,
cr_MissingTermBuf = 8
};
class Cachedb {
public:
void reset();
bool init ( );
bool init2 ( int32_t treeMem );
bool verify ( char *coll );
bool addColl ( char *coll, bool doVerify = true );
char getTypeFromKey ( char *key ) { return key[3]; }
// url and content hashes are the args
key_t makeStartKey ( int32_t uh32 , int32_t ch32 ) {
key_t k;
k.n1 = (uint32_t)uh32;
// clear hi bit, set hi bit when storing query results
// not not these
//k.n1 &= 0x7fffffff;
k.n0 = (uint32_t)ch32;
k.n0 <<= 32;
// del key
k.n0 &= 0xfffffffffffffffeLL;
return k;
};
key_t makeEndKey ( int32_t uh32 , int32_t ch32 ) {
key_t k;
k.n1 = (uint32_t)uh32;
// clear hi bit, set hi bit when storing query results
// not not these
//k.n1 &= 0x7fffffff;
k.n0 = (uint32_t)ch32;
// max object type i guess
k.n0 <<= 8;
k.n0 |= 0xff;
k.n0 <<= 24;
// not a del key
k.n0 |= 0x01;
return k;
};
key_t makeStartKey2 ( int32_t uh32 , int32_t ch32 , int32_t objectType ) {
key_t k = makeKey ( uh32 , ch32 , objectType );
// del key
k.n0 &= 0xfffffffffffffffeLL;
return k;
};
key_t makeEndKey2 ( int32_t uh32 , int32_t ch32 , int32_t objectType ) {
key_t k = makeKey ( uh32 , ch32 , objectType );
// not a del key
k.n0 |= 0x01;
return k;
};
key_t makeKey ( int32_t uh32 , int32_t ch32 , uint8_t objectType ) {
key_t k;
k.n1 = (uint32_t)uh32;
// clear hi bit, set hi bit when storing query results
// not not these
//k.n1 &= 0x7fffffff;
k.n0 = (uint32_t)ch32;
k.n0 <<= 8;
k.n0 |= objectType; // 1 byte
k.n0 <<= 24;
// not a del key
k.n0 |= 0x01;
return k;
};
char *m_name;
char m_rdbId;
Rdb *getRdb() { return &m_rdb; };
//DiskPageCache *getDiskPageCache () { return &m_pc; };
//DiskPageCache m_pc;
private:
Rdb m_rdb;
};
extern class Cachedb g_cachedb;
extern class Cachedb g_serpdb;
#endif