simongog / sdsl-lite

Succinct Data Structure Library 2.0
Other
2.21k stars 350 forks source link

building csa for an integer vector #257

Closed ekg closed 9 years ago

ekg commented 9 years ago

How does one build a compressed suffix array from an integer vector? For instance, I try:

construct_im(e_csa, e_iv, 1);

Where e_iv is an integer vector composed of non-zero 64-bit integers (size_t).

When I try to run this code, I get:

terminate called after throwing an instance of 'std::logic_error'
  what():  Error: File "@15687_5" contains zero symbol.

I can see how to build the CSA for strings, and got that to work fine, but don't see how to do this. Is the CSA implementation limitation to strings? Any documentation or example code would be greatly appreciated! What is already here is wonderful.

simongog commented 9 years ago

Hi Erik,

the vector should not contain a zero (since zero is appended as sentinel at the end of the text). Here is an example:

#include <sdsl/suffix_arrays.hpp>
#include <iostream>

using namespace sdsl;
using namespace std;

int main(){
    csa_wt_int<> csa;
    int_vector<> text = {1,2,3,2,4,5,100,4,3};
    construct_im(csa, text, 0);
    cout << "csa=" << csa << endl;
    cout << "text=" << csa.text << endl;
}