code: private int findP(long p) {
          // p need not occur as a root primary.
          // For example, it might be a reordering group boundary.
          assert((p >> 24) != Collation.UNASSIGNED_IMPLICIT_BYTE);
          // modified binary search
          int start = (int)elements[IX_FIRST_PRIMARY_INDEX];
          assert(p >= elements[start]);
          int limit = elements.length - 1;
          assert(elements[limit] >= PRIMARY_SENTINEL);
          assert(p < elements[limit]);
          while((start + 1) < limit) {
              // Invariant: elements[start] and elements[limit] are primaries,
              // and elements[start]<=p<=elements[limit].
              int i = (int)(((long)start + (long)limit) / 2);
              long q = elements[i];
              if((q & SEC_TER_DELTA_FLAG) != 0) {
                  // Find the next primary.
                  int j = i + 1;
                  for(;;) {
                      if(j == limit) { break; }
                      q = elements[j];
                      if((q & SEC_TER_DELTA_FLAG) == 0) {
                          i = j;
                          break;
                      }
                      ++j;
                  }
                  if((q & SEC_TER_DELTA_FLAG) != 0) {
                      // Find the preceding primary.
                      j = i - 1;
                      for(;;) {
                          if(j == start) { break; }
                          q = elements[j];
                          if((q & SEC_TER_DELTA_FLAG) == 0) {
                              i = j;
                              break;
                          }
                          --j;
                      }
                      if((q & SEC_TER_DELTA_FLAG) != 0) {
                          // No primary between start and limit.
                          break;
                      }
                  }
              }
              if(p < (q & 0xffffff00L)) {  // Reset the "step" bits of a range end primary.
                  limit = i;
              } else {
                  start = i;
              }
          }
          return start;
      }
docs: Finds the largest index i where elements[i]<=p.
  Requires first primary<=p<0xffffff00 (PRIMARY_SENTINEL).
  Does not require that p is a root collator primary.