/*
* call-seq:
* sarray.array -> Array
*
* Returns a copy of the internal suffix array as an Array of Fixnum objects. This
* array is a copy so you're free to mangle it however you wish.
*
* A suffix array is the sequence of indices into the source that mark each suffix
* as if they were sorted.
*/
static VALUE SuffixArray_array(VALUE self)
{
SuffixArray *sa = NULL;
Data_Get_Struct(self, SuffixArray, sa);
if(sa == NULL || sa->suffix_index == NULL || RSTRING(sa->source)->len == 0) {
rb_raise(cSAError, ERR_NOT_INITIALIZED);
}
// get the length of the suffix index
size_t source_len = RSTRING(sa->source)->len;
size_t i = 0;
VALUE result = rb_ary_new();
for(i = 0; i < source_len; i++) {
rb_ary_push(result, INT2FIX(sa->suffix_index[i]));
}
return result;
}