suffix arrays

Can any one please explain me what is happening in the suffix array nlogn algorithm from line 59 to 89
I cant understand what is the significance of bh2,cnt arrays?
link:fjbYBr - Online C++ Compiler & Debugging Tool - Ideone.com