code: private void ssMergeForward(int PA, int first, int middle, int last, int buf,
                                  int depth) {
          // PA, first, middle, last, buf are pointers to SA
          int a, b, c, bufend;// pointers to SA
          int t, r;
  
          bufend = buf + (middle - first) - 1;
          ssBlockSwap(buf, first, middle - first);
  
          for (t = SA[a = first], b = buf, c = middle; ; ) {
              r = ssCompare(PA + SA[b], PA + SA[c], depth);
              if (r < 0) {
                  do {
                      SA[a++] = SA[b];
                      if (bufend <= b) {
                          SA[bufend] = t;
                          return;
                      }
                      SA[b++] = SA[a];
                  }
                  while (SA[b] < 0);
              } else if (r > 0) {
                  do {
                      SA[a++] = SA[c];
                      SA[c++] = SA[a];
                      if (last <= c) {
                          while (b < bufend) {
                              SA[a++] = SA[b];
                              SA[b++] = SA[a];
                          }
                          SA[a] = SA[b];
                          SA[b] = t;
                          return;
                      }
                  }
                  while (SA[c] < 0);
              } else {
                  SA[c] = ~SA[c];
                  do {
                      SA[a++] = SA[b];
                      if (bufend <= b) {
                          SA[bufend] = t;
                          return;
                      }
                      SA[b++] = SA[a];
                  }
                  while (SA[b] < 0);
  
                  do {
                      SA[a++] = SA[c];
                      SA[c++] = SA[a];
                      if (last <= c) {
                          while (b < bufend) {
                              SA[a++] = SA[b];
                              SA[b++] = SA[a];
                          }
                          SA[a] = SA[b];
                          SA[b] = t;
                          return;
                      }
                  }
                  while (SA[c] < 0);
              }
          }
  
      }
docs: Merge-forward with internal buffer.