>>112
BOOL block_sort_e(const BYTE* src,BYTE* dst,size_t size,unsigned int* index)
{
 unsigned int i;
 unsigned int* offset = NULL;

 assert(size > 1);
 assert(src != dst);
 assert(src != NULL && dst != NULL);

 offset = (unsigned int*)calloc(65536, sizeof(unsigned int));

 if (offset == NULL)
  return FALSE;
 
 for (i = 0; i < size - 1; i++) {
  unsigned int index = src[i] << 8 | src[i + 1];
  offset[index]++;
 }
 offset[src[size - 1] << 8 | src[0]]++;

 for (i = 1; i < 65536; i++)
  offset[i] += offset[i - 1];

 dst[ --offset[src[size - 1] << 8 | src[0]] ] = src[size - 2];
 for (i = size - 2; i; i--) {
  WORD idx = src[i] << 8 | src[i + 1];
  dst[--offset[idx]] = src[i - 1];
 }
 *index = --offset[src[0] << 8 | src[1]];
 dst[*index] = src[size - 1];

 free(offset);

 return TRUE;
}