-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcpsamples.h
86 lines (60 loc) · 1.8 KB
/
lcpsamples.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
#ifndef LCPSAMPLES_H
#define LCPSAMPLES_H
#include <cstdio>
#include <fstream>
#ifdef SUCCINCT_LCP_VECTOR
#include "bits/succinctvector.h"
#else
#include "bits/deltavector.h"
#endif
#include "bits/array.h"
#include "misc/utils.h"
namespace CSA
{
#ifdef SUCCINCT_LCP_VECTOR
typedef SuccinctVector LCPVector;
#else
typedef DeltaVector LCPVector;
#endif
class LCPSamples
{
public:
#ifdef SUCCINCT_LCP_VECTOR
const static usint INDEX_BLOCK_SIZE = 32;
#else
const static usint INDEX_BLOCK_SIZE = 16;
#endif
const static usint VALUE_BLOCK_SIZE = 32;
explicit LCPSamples(std::ifstream& sample_file);
explicit LCPSamples(FILE* sample_file);
// Input pairs are of form (i, LCP[i]).
LCPSamples(pair_type* input, usint _size, usint _items, bool report = false, bool free_input = false);
LCPSamples(LCPVector::Encoder& index_encoder, ArrayEncoder& value_encoder, usint _size);
~LCPSamples();
void writeTo(std::ofstream& sample_file) const;
void writeTo(FILE* file) const;
inline bool isSampled(usint sa_index) const
{
LCPVector::Iterator iter(*(this->indexes));
return iter.isSet(sa_index);
}
// Behavior is undefined if there is no sample at index.
inline usint getSampleAt(usint sa_index) const
{
LCPVector::Iterator index_iter(*(this->indexes));
Array::Iterator value_iter(*(this->values));
return value_iter.getItem(index_iter.rank(sa_index) - 1) - 1;
}
inline usint getNumberOfSamples() const { return this->items; }
usint reportSize() const;
private:
usint size, items;
LCPVector* indexes;
Array* values;
// These are not allowed.
LCPSamples();
LCPSamples(const LCPSamples&);
LCPSamples& operator = (const LCPSamples&);
};
} // namespace CSA
#endif // LCPSAMPLES_H