-
Notifications
You must be signed in to change notification settings - Fork 1
/
kyoto_reader.cpp
48 lines (39 loc) · 905 Bytes
/
kyoto_reader.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
#include <kcpolydb.h>
#include <chrono>
#include <string>
#include <iostream>
using namespace std;
using namespace kyotocabinet;
class IntComparator final : public Comparator
{
public:
explicit IntComparator()
{
}
int32_t compare(const char* akbuf, size_t aksiz, const char* bkbuf, size_t bksiz) override
{
int64_t ai, bi;
memcpy(&ai, akbuf, aksiz);
memcpy(&bi, bkbuf, bksiz);
return (ai - bi);
}
};
// main routine
int main(int argc, char** argv)
{
TreeDB db;
IntComparator cmp;
db.tune_comparator(&cmp);
if (!db.open("casket.kch", PolyDB::OREADER))
{
cerr << "open error: " << db.error().name() << endl;
return 1;
}
DB::Cursor* cur = db.cursor();
cur->jump_back(std::to_string(55));
std::string val;
cur->get_value(&val);
cout << val << endl;
db.close();
return 0;
}