BinTree.h 1.72 KB
Newer Older
nkindlon's avatar
nkindlon committed
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
/*
 * BinTree.h
 *
 *  Created on: Jan 5, 2013
 *      Author: nek3d
 */

#ifndef BINTREE_H_
#define BINTREE_H_

using namespace std;

#include <stdint.h>
#include <string>
#include <set>
#include <map>

#include "QuickString.h"
#include "RecordKeyList.h"
#include "Context.h"

class FileRecordMgr;
class Record;

class BinTree {
public:
	BinTree(int databaseFileIdx, Context *context);

	~BinTree();
	bool loadDB();
	void getHits(Record *record, RecordKeyList &hitSet);


private:

	int _databaseFileIdx;
	Context *_context;

    //
    // BIN HANDLING
    //
	static const uint32_t NUM_BINS = 37450;
	static const uint32_t NUM_BIN_LEVELS = 7;

	// bins range in size from 16kb to 512Mb
	// Bin  0          spans 512Mbp,   # Level 1
	// Bins 1-8        span 64Mbp,     # Level 2
	// Bins 9-72       span 8Mbp,      # Level 3
	// Bins 73-584     span 1Mbp       # Level 4
	// Bins 585-4680   span 128Kbp     # Level 5
	// Bins 4681-37449 span 16Kbp      # Level 6
	uint32_t *_binOffsetsExtended;
	static const uint32_t _binFirstShift = 14;       /* How much to shift to get to finest bin. */
	static const uint32_t _binNextShift  = 3;        /* How much to shift to get to next larger bin. */

	typedef BTlist<const Record *> innerListType;
	typedef const BTlistNode<const Record *> * innerListIterType;
	typedef innerListType * binType;
	typedef binType * allBinsType;
	typedef QuickString mainKeyType;
	typedef map<mainKeyType, allBinsType> mainMapType;
	mainMapType _mainMap;

	FileRecordMgr *_dbFileMgr;

	bool _showBinMetrics;
	uint32_t _maxBinNumFound;
	map<uint32_t, int> _binsHit;

	bool addRecordToTree(const Record *);
	uint32_t getBin(uint32_t start, uint32_t end) const;
	uint32_t getBin(const Record *record) const;


};


#endif /* BINTREE_H_ */