I have tried going through the theory in the paper http://webglimpse.net/pubs/suffix.pdf
But I am kind of lost when they say
Let Ai be the first suffix in the first bucket (i.e., Pos[0] = i), and consider Ai-h (if i-h < 0, then we ignore Ai and take the suffix of Pos[1], and so on). Since Ai starts with the smallest h-symbol string, Ai-h should be the first in its 2h-bucket.
I am not able to understand this statement. Why Ai-h can be ignored if i-h < 0. How the position is getting determined in const time when i-h > 0 in the phase 1?
One sample impl is http://belbesy.wordpress.com/2012/10/10/spoj-649-distinct-substrings-suffix-arrays-nlgn/