6 #include "bits/vectors.h"
8 #include "misc/parameters.h"
15 const std::string SA_EXTENSION = ".sa";
16 const std::string PSI_EXTENSION = ".psi";
17 const std::string ARRAY_EXTENSION = ".rlcsa.array";
18 const std::string SA_SAMPLES_EXTENSION = ".rlcsa.sa_samples";
19 const std::string PARAMETERS_EXTENSION = ".rlcsa.parameters";
22 const parameter_type RLCSA_BLOCK_SIZE = parameter_type("RLCSA_BLOCK_SIZE", 32);
23 const parameter_type SAMPLE_RATE = parameter_type("SAMPLE_RATE", 512);
24 const parameter_type SUPPORT_LOCATE = parameter_type("SUPPORT_LOCATE", 0);
25 const parameter_type SUPPORT_DISPLAY = parameter_type("SUPPORT_DISPLAY", 0);
40 const static usint ENDPOINT_BLOCK_SIZE = 16;
42 RLCSA(const std::string& base_name, bool print = false);
45 If multiple_sequences is true, each 0 is treated as a end of sequence marker.
46 There must be nonzero characters between the 0s. data[bytes - 1] must also be 0.
48 RLCSA(uchar* data, usint bytes, usint block_size, usint sa_sample_rate, bool multiple_sequences, bool delete_data);
50 // Destroys contents of index and increment.
51 RLCSA(RLCSA& index, RLCSA& increment, usint* positions, usint block_size);
54 void writeTo(const std::string& base_name);
58 // Returns the closed interval of suffix array containing the matches.
59 pair_type count(const std::string& pattern);
61 void reportPositions(uchar* data, usint length, usint* positions);
63 // Returns SA[range]. User must free the buffer. Latter version uses buffer provided by the user.
64 LocateItem* locate(pair_type range);
65 LocateItem* locate(pair_type range, LocateItem* data);
68 usint locate(usint index);
70 // Returns Ti[range]. User must free the buffer. Latter version uses buffer provided by the user.
71 uchar* display(usint sequence, pair_type range);
72 uchar* display(usint sequence, pair_type range, uchar* data);
74 // Writes the Psi array into given file. End of sequence markers are not written.
75 void decompressInto(std::ofstream& psi_file);
77 // Returns the BWT of the collection including end of sequence markers.
80 // Return value includes the implicit end of sequence markers. To get suffix array indexes,
81 // subtract getNumberOfSequences() from the value.
82 usint psi(usint index);
83 pair_type psi(usint index, usint max_length); // This version returns a run.
85 inline bool supportsLocate() { return this->support_locate; }
86 inline bool supportsDisplay() { return this->support_display; }
87 inline usint getSize() { return this->data_size; }
88 inline usint getNumberOfSequences() { return this->number_of_sequences; }
90 pair_type getSequence(usint number);
92 // Returns the size of the data structure.
93 usint reportSize(bool print = false);
98 RLEVector* array[CHARS];
99 SASamples* sa_samples;
101 pair_type index_ranges[CHARS];
104 usint text_chars[CHARS]; // which characters are present in the text
107 usint index_pointers[CHARS]; // which of the above is at i * index_rate
110 bool support_locate, support_display;
113 usint number_of_sequences;
114 DeltaVector* end_points;
116 void locateUnsafe(pair_type range, LocateItem* data);
117 bool processRun(pair_type run, LocateItem* data);
118 void displayUnsafe(pair_type range, uchar* data);
120 inline usint getCharacter(usint pos)
122 usint* curr = &(this->text_chars[this->index_pointers[pos / this->index_rate]]);
123 while(pos > this->index_ranges[*curr].second) { curr++; }
127 void buildCharIndexes(usint* distribution);
131 // Returns the total number of characters.
132 usint buildRanges(usint* distribution, pair_type* index_ranges);