-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.h
More file actions
106 lines (91 loc) · 2.14 KB
/
Copy pathformat.h
File metadata and controls
106 lines (91 loc) · 2.14 KB
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
#ifndef FORMAT_H_
#define FORMAT_H_
#include <deque>
#include <set>
#include <iostream>
#include <string>
#include <map>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <inttypes.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <assert.h>
#include <time.h>
#include <iostream>
#include <fstream>
using namespace std;
namespace levelque {
enum RecordType {
// Zero is reserved for preallocated files
kZeroType = 0,
kFullType = 1,
// For fragments
kFirstType = 2,
kMiddleType = 3,
kLastType = 4
};
static const int kMaxRecordType = kLastType;
static const uint32_t kBlockSize = 32768;
// Header is checksum (4 bytes), type (1 byte), length (2 bytes), itemid(4 bytes).
static const uint8_t kHeaderSize = 4 + 1 + 2 + 4;
enum FileStatus {
//the files that not are used
fUnUse = 1,
//the files used,already readed
fUse = 0,
//the file using
fUsing = 2
};
static const int fNum = 100;
static const uint32_t fMaxBlockNum = 1000; //65535;
//the num of level for reading priority
static const uint8_t levelNum = 9;
//memory buffer size
static const uint64_t mMaxBufferSize = 1024*1024*1; //10M
typedef uint16_t FileId;
typedef uint32_t ItemNumber;
typedef uint64_t TimeId;
typedef struct filepos{
FileId id;
uint32_t blockid;
uint32_t offset;
ItemNumber curpos;
struct filepos& operator= (struct filepos &s) {
id = s.id;
blockid = s.blockid;
offset = s.offset;
curpos = s.curpos;
return *this;
}
}filePos;
typedef std::map<TimeId, filePos> FILELIST;
class QueueFileName
{
public:
static void List(FileId id, std::string &filename, uint8_t levelid=0) {
char buf[50] = {0};
sprintf(buf,"queue_%04d_%d.lst", id, levelid);
filename = buf;
}
static void Head(std::string &filename,uint8_t levelid=0) {
char buf[50] = {0};
sprintf(buf,"head_%d.lst", levelid);
filename = buf;
}
static void Level(std::string &filename) {
filename = "level.hst";
}
};
}
#endif