Debug swcsa
[SXSI/TextCollection.git] / incbwt / bits / deltavector.h
1 #ifndef DELTAVECTOR_H
2 #define DELTAVECTOR_H
3
4 #include <fstream>
5
6 #include "bitvector.h"
7
8
9 namespace CSA
10 {
11
12
13 /*
14   This class is used to construct a DeltaVector.
15 */
16
17 class DeltaEncoder : public VectorEncoder
18 {
19   public:
20     DeltaEncoder(usint block_bytes, usint superblock_size = VectorEncoder::SUPERBLOCK_SIZE);
21     ~DeltaEncoder();
22
23     void setBit(usint value);
24     void setRun(usint start, usint len);
25
26     // These versions are just for compatibility with RLEVector.
27     void addBit(usint value);
28     void addRun(usint start, usint len);
29     void flush(); // Does nothing.
30
31   protected:
32
33     // These are not allowed.
34     DeltaEncoder();
35     DeltaEncoder(const DeltaEncoder&);
36     DeltaEncoder& operator = (const DeltaEncoder&);
37 };
38
39
40 /*
41   This is a gap-encoded bit vector using delta coding.
42 */
43
44 class DeltaVector : public BitVector
45 {
46   public:
47     typedef DeltaEncoder Encoder;
48
49     DeltaVector(std::ifstream& file);
50     DeltaVector(std::FILE * file);
51     DeltaVector(Encoder& encoder, usint universe_size);
52     ~DeltaVector();
53
54 //--------------------------------------------------------------------------
55
56     usint reportSize() const;
57
58 //--------------------------------------------------------------------------
59
60     class Iterator : public BitVector::Iterator
61     {
62       public:
63         Iterator(const DeltaVector& par);
64         ~Iterator();
65
66         usint rank(usint value, bool at_least = false);
67
68         usint select(usint index);
69         usint selectNext();
70
71         pair_type valueAfter(usint value);
72         pair_type nextValue();
73
74         pair_type selectRun(usint index, usint max_length);
75         pair_type selectNextRun(usint max_length);
76
77         bool isSet(usint value);
78
79         // Counts the number of 1-bit runs.
80         usint countRuns();
81
82       protected:
83
84         // These are not allowed.
85         Iterator();
86         Iterator(const Iterator&);
87         Iterator& operator = (const Iterator&);
88     };
89
90 //--------------------------------------------------------------------------
91
92   protected:
93
94     // These are not allowed.
95     DeltaVector();
96     DeltaVector(const DeltaVector&);
97     DeltaVector& operator = (const DeltaVector&);
98 };
99
100
101 } // namespace CSA
102
103
104 #endif // DELTAVECTOR_H