-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuffixarray.h
28 lines (24 loc) · 1.05 KB
/
suffixarray.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
#ifndef SUFFIXARRAY_H_INCLUDED
#define SUFFIXARRAY_H_INCLUDED
#include "general.h"
#include "str.h"
immutable_class SuffixArray {
private:
const Str& str; // corresponding string
const unsigned* arr; // array of suffix positions
unsigned logStep; // shift step when sparse, 0 when not
unsigned sparseMask; // mask for checking if the value is held; step = sparseMask + 1
public:
SuffixArray(const Str& str, unsigned step = 1);
~SuffixArray() { /* destroy(); */ } // destroyed by controlling FM string
inline unsigned length() const { return (str.len >> logStep) + 1; }
const int operator[](int i) const;
SuffixArray sparse(unsigned step, bool keepOriginal = true);
void destroy();
private:
SuffixArray(const Str& str, unsigned* arr, unsigned logStep, unsigned sparseMask):
str(str), arr(arr), logStep(logStep), sparseMask(sparseMask) {}
friend std::ostream& operator<<(std::ostream& os, const SuffixArray& sufArr);
friend class StrFact;
};
#endif // SUFFIXARRAY_H_INCLUDED