/**
 * postSort() runs after the sort has been performed. For HphpArray, postSort()
 * handles rebuilding the hash. Also, if resetKeys is true, postSort() will
 * renumber the keys 0 thru n-1.
 */
void HphpArray::postSort(bool resetKeys) {
  assert(m_size > 0);
  size_t tableSize = computeTableSize(m_tableMask);
  initHash(m_hash, tableSize);
  m_hLoad = 0;
  if (resetKeys) {
    for (uint32_t pos = 0; pos < m_used; ++pos) {
      Elm* e = &m_data[pos];
      if (e->hasStrKey()) decRefStr(e->key);
      e->setIntKey(pos);
      m_hash[pos] = pos;
    }
    m_nextKI = m_size;
  } else {
    for (uint32_t pos = 0; pos < m_used; ++pos) {
      Elm* e = &m_data[pos];
      ElmInd* ei = findForNewInsert(e->hasIntKey() ? e->ikey : e->hash());
      *ei = pos;
    }
  }
  m_hLoad = m_size;
}
/**
 * postSort() runs after the sort has been performed. For HphpArray, postSort()
 * handles rebuilding the hash. Also, if resetKeys is true, postSort() will
 * renumber the keys 0 thru n-1.
 */
void HphpArray::postSort(bool resetKeys) {
  ASSERT(m_size > 0);
  size_t tableSize = computeTableSize(m_tableMask);
  initHash(m_hash, tableSize);
  m_hLoad = 0;
  if (resetKeys) {
    for (ElmInd pos = 0; pos <= m_lastE; ++pos) {
      Elm* e = &m_data[pos];
      if (e->hasStrKey() && e->key->decRefCount() == 0) {
        e->key->release();
      }
      e->setIntKey(pos);
      m_hash[pos] = pos;
    }
    m_nextKI = m_size;
  } else {
    for (ElmInd pos = 0; pos <= m_lastE; ++pos) {
      Elm* e = &m_data[pos];
      ElmInd* ei = findForNewInsert(e->hasIntKey() ? e->ikey : e->hash);
      *ei = pos;
    }
  }
  m_hLoad = m_size;
}