code: private void ssHeapSort(int Td, int PA, int sa, int size) {
          int i, m, t;
  
          m = size;
          if ((size % 2) == 0) {
              m--;
              if (T[start + Td + SA[PA + SA[sa + (m / 2)]]] < T[start + Td
                  + SA[PA + SA[sa + m]]]) {
                  swapInSA(sa + m, sa + (m / 2));
              }
          }
  
          for (i = m / 2 - 1; 0 <= i; --i) {
              ssFixDown(Td, PA, sa, i, m);
          }
          if ((size % 2) == 0) {
              swapInSA(sa, sa + m);
              ssFixDown(Td, PA, sa, 0, m);
          }
          for (i = m - 1; 0 < i; --i) {
              t = SA[sa];
              SA[sa] = SA[sa + i];
              ssFixDown(Td, PA, sa, 0, i);
              SA[sa + i] = t;
          }
  
      }
docs: Simple top-down heapsort.