Debug swcsa
[SXSI/TextCollection.git] / incbwt / lcpsamples.h
1 #ifndef LCPSAMPLES_H
2 #define LCPSAMPLES_H
3
4 #include <fstream>
5
6
7 #include "bits/deltavector.h"
8 #include "bits/rlevector.h"
9 #include "bits/nibblevector.h"
10
11 #include "bits/array.h"
12 #include "misc/utils.h"
13
14
15 namespace CSA
16 {
17
18
19 class LCPSamples
20 {
21   public:
22     const static usint INDEX_BLOCK_SIZE = 16;
23     const static usint VALUE_BLOCK_SIZE = 32;
24
25     LCPSamples(std::ifstream& sample_file);
26
27     // Input pairs are of form (i, LCP[i]).
28     LCPSamples(pair_type* input, usint _size, usint _items, bool report = false, bool free_input = false);
29
30     LCPSamples(DeltaEncoder& index_encoder, ArrayEncoder& value_encoder, usint _size);
31
32     ~LCPSamples();
33
34     void writeTo(std::ofstream& sample_file) const;
35
36     // Returns the value of the ith sample in suffix array order.
37     // If the index is invalid, returns this->size.
38     inline usint getSample(usint i) const
39     {
40       Array::Iterator iter(*(this->values));
41       usint tmp = iter.getItem(i);
42       if(tmp == 0) { return this->size; }
43       return tmp - 1;
44     }
45
46     // Returns (ind, sample number) where ind >= index or (size, ???).
47     inline pair_type getFirstSampleAfter(usint index) const
48     {
49       DeltaVector::Iterator iter(*(this->indexes));
50       return iter.valueAfter(index);
51     }
52
53     // Behavior is undefined if there is no sample at index.
54     inline usint getSampleAtPosition(usint index) const
55     {
56       DeltaVector::Iterator index_iter(*(this->indexes));
57       Array::Iterator value_iter(*(this->values));
58       return value_iter.getItem(index_iter.rank(index) - 1) - 1;
59     }
60
61     inline usint getNumberOfSamples() const { return this->items; }
62
63     usint reportSize() const;
64
65   private:
66     usint size, items;
67
68     DeltaVector* indexes;
69     Array*       values;
70
71     // These are not allowed.
72     LCPSamples();
73     LCPSamples(const LCPSamples&);
74     LCPSamples& operator = (const LCPSamples&);
75 };
76
77
78 } // namespace CSA
79
80
81 #endif // LCPSAMPLES_H