code: public static int writeIdenticalLevelRun(int prev, CharSequence s, int i, int length, ByteArrayWrapper sink) {
          while (i < length) {
              // We must have capacity>=SLOPE_MAX_BYTES in case writeDiff() writes that much,
              // but we do not want to force the sink to allocate
              // for a large min_capacity because we might actually only write one byte.
              ensureAppendCapacity(sink, 16, s.length() * 2);
              byte[] buffer = sink.bytes;
              int capacity = buffer.length;
              int p = sink.size;
              int lastSafe = capacity - SLOPE_MAX_BYTES_;
              while (i < length && p <= lastSafe) {
                  if (prev < 0x4e00 || prev >= 0xa000) {
                      prev = (prev & ~0x7f) - SLOPE_REACH_NEG_1_;
                  } else {
                      // Unihan U+4e00..U+9fa5:
                      // double-bytes down from the upper end
                      prev = 0x9fff - SLOPE_REACH_POS_2_;
                  }
  
                  int c = Character.codePointAt(s, i);
                  i += Character.charCount(c);
                  if (c == 0xfffe) {
                      buffer[p++] = 2;  // merge separator
                      prev = 0;
                  } else {
                      p = writeDiff(c - prev, buffer, p);
                      prev = c;
                  }
              }
              sink.size = p;
          }
          return prev;
      }
docs: Encode the code points of a string as
  a sequence of byte-encoded differences (slope detection),
  preserving lexical order.
  
  <p>Optimize the difference-taking for runs of Unicode text within
  small scripts:
  
  <p>Most small scripts are allocated within aligned 128-blocks of Unicode
  code points. Lexical order is preserved if "prev" is always moved
  into the middle of such a block.
  
  <p>Additionally, "prev" is moved from anywhere in the Unihan
  area into the middle of that area.
  Note that the identical-level run in a sort key is generated from
  NFD text - there are never Hangul characters included.