-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlcqs.h
111 lines (91 loc) · 2.28 KB
/
lcqs.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
/***
@author: Jiabing Fu, Bixin Ke, Shoubin Dong.
@date:2019.07.14
@institute: South China University of Technology
@Paper: Published in BMC Bioinformatics 2020.
***/
#ifndef LCQS_H
#define LCQS_H
#include "libzpaq.h"
#include <vector>
#include <string>
#include <cstdio>
#include <unordered_map>
namespace lcqs {
typedef pthread_t ThreadID; // job ID type
class CompressJob;
struct param {
int k;
double threshold;
const char* out_name;
param():k(4), threshold(0.1){}
void set_threshold(double s) {
if(s < 0.) s = 0.;
if(s > 1.) s = 1.;
threshold = s;
}
void set_k(int _k) {
if(_k < 1) _k = 1;
if(_k > 6) _k = 6;
k = _k;
}
void set_outname(const char* s) {
out_name = s;
}
void set_inname(const char* s) {
freopen(s, "r", stdin);
}
};
struct format {
char score;
int32_t qlen[2];
void write(FILE* f) {
fwrite(&score, sizeof score, 1, f);
fwrite(qlen, 4, 2, f);
}
void read(FILE* f) {
fread(&score, sizeof score, 1, f);
fread(qlen, 4, 2, f);
}
};
class compressor {
param par;
format fmt;
int threads;
std::vector<std::string> qs_raw;
CompressJob* job;
std::vector<ThreadID> tid;
ThreadID wid;
void get_score(const std::vector<std::string>& sample);
double get_table(const std::vector<std::string>& sample, std::unordered_map<long long, double>& table, int k);
public:
compressor(int _threads);
void init(param _par);
void write_format(FILE* f) { fmt.write(f); }
void end();
void qs_compress();
};
class ExtractJob;
class decompressor {
format fmt;
int threads;
std::vector<std::string> qs_raw[2];
ExtractJob* job;
std::vector<ThreadID> tid;
void start();
void end();
void get_block(uint32_t l, uint32_t r);
public:
decompressor(int _threads);
void open(char* s);
void read_format();
void read_content();
void close();
void qs_add(libzpaq::StringBuffer& q, int i);
void get_qs();
void query(uint32_t L, uint32_t R);
void read_table();
void set_out(const char* s);
};
}
#endif // LCQS_H