Store index in word for stable sort

In FreeBSD, the compare function for qsort() cannot use address to
implement stable sort because the address passed to compare function is
not the original one. Thus we change to use index instead of address to
implement stable sort.

See [1] for more information.

[1] https://groups.google.com/d/msg/chewing-devel/cUovLo0zGuc/-t2S3OfMDcYJ