You are reading a single comment by @TiCPU and its replies. Click here to read the full conversation.
  • And here is my final code for my needs, this won't stack overflow:

    nqsort: 425.1626749999999788087 (0.343325)

    // Non-nested quick sort
    Array.prototype.nqsort = function(depth) {
      var pivot, i=0, left, right;
      if (depth === undefined) {
        depth = parseInt(Math.floor(this.length/5), 10);
      }
      var begin = Uint16Array(depth);
      var end = Uint16Array(depth);
    
      begin[0] = 0;
      end[0] = this.length;
    
      while (i >= 0) {
        left = begin[i]; right = end[i]-1;
        if (left < right) {
          pivot = this[left];
          if (i === depth-1) return false;
          while (left < right) {
            while (this[right] >= pivot && left < right) right--;
            if (left < right) this[left++] = this[right];
            while (this[left] <= pivot && left < right) left++;
            if (left < right) this[right--] = this[left];
          }
          this[left] = pivot; begin[i+1] = left+1;
          end[i+1] = end[i]; end[i++] = left;
        } else i--;
      }
      return true;
    };
    Uint16Array.prototype.nqsort = Array.prototype.nqsort;
    

    References: http://alienryderflex.com/quicksort/

About

Avatar for TiCPU @TiCPU started