code: static final void quickSelectAndRebuild(final WritableMemory mem, final int preambleLongs,
        final int lgNomLongs) {
      //Note: This copies the Memory data onto the heap and then at the end copies the result
      // back to Memory. Even if we tried to do this directly into Memory it would require pre-clearing,
      // and the internal loops would be slower. The bulk copies are performed at a low level and
      // are quite fast. Measurements reveal that we are not paying much of a penalty.
  
      //Pull data into tmp arr for QS algo
      final int lgArrLongs = extractLgArrLongs(mem);
      final int curCount = extractCurCount(mem);
      final int arrLongs = 1 << lgArrLongs;
      final long[] tmpArr = new long[arrLongs];
      final int preBytes = preambleLongs << 3;
      mem.getLongArray(preBytes, tmpArr, 0, arrLongs); //copy mem data to tmpArr
  
      //Do the QuickSelect on a tmp arr to create new thetaLong
      final int pivot = (1 << lgNomLongs) + 1; // (K+1) pivot for QS
      final long newThetaLong = selectExcludingZeros(tmpArr, curCount, pivot);
      insertThetaLong(mem, newThetaLong); //UPDATE thetalong
  
      //Rebuild to clean up dirty data, update count
      final long[] tgtArr = new long[arrLongs];
      final int newCurCount =
          HashOperations.hashArrayInsert(tmpArr, tgtArr, lgArrLongs, newThetaLong);
      insertCurCount(mem, newCurCount); //UPDATE curCount
  
      //put the rebuilt array back into memory
      mem.putLongArray(preBytes, tgtArr, 0, arrLongs);
    }
docs: Rebuild the hashTable in the given Memory at its current size. Changes theta and thus count.
  This assumes a Memory preamble of standard form with correct values of curCount and thetaLong.
  ThetaLong and curCount will change.
  Afterwards, caller must update local class members curCount and thetaLong from Memory.
  
  @param mem the Memory the given Memory
  @param preambleLongs size of preamble in longs
  @param lgNomLongs the log_base2 of k, the configuration parameter of the sketch