code: long lastCEWithPrimaryBefore(long p) {
          if(p == 0) { return 0; }
          assert(p > elements[(int)elements[IX_FIRST_PRIMARY_INDEX]]);
          int index = findP(p);
          long q = elements[index];
          long secTer;
          if(p == (q & 0xffffff00L)) {
              // p == elements[index] is a root primary. Find the CE before it.
              // We must not be in a primary range.
              assert((q & PRIMARY_STEP_MASK) == 0);
              secTer = elements[index - 1];
              if((secTer & SEC_TER_DELTA_FLAG) == 0) {
                  // Primary CE just before p.
                  p = secTer & 0xffffff00L;
                  secTer = Collation.COMMON_SEC_AND_TER_CE;
              } else {
                  // secTer = last secondary & tertiary for the previous primary
                  index -= 2;
                  for(;;) {
                      p = elements[index];
                      if((p & SEC_TER_DELTA_FLAG) == 0) {
                          p &= 0xffffff00L;
                          break;
                      }
                      --index;
                  }
              }
          } else {
              // p > elements[index] which is the previous primary.
              // Find the last secondary & tertiary weights for it.
              p = q & 0xffffff00L;
              secTer = Collation.COMMON_SEC_AND_TER_CE;
              for(;;) {
                  q = elements[++index];
                  if((q & SEC_TER_DELTA_FLAG) == 0) {
                      // We must not be in a primary range.
                      assert((q & PRIMARY_STEP_MASK) == 0);
                      break;
                  }
                  secTer = q;
              }
          }
          return (p << 32) | (secTer & ~SEC_TER_DELTA_FLAG);
      }
docs: Returns the last root CE with a primary weight before p.
  Intended only for reordering group boundaries.