code: private static final int binarySearchForRootPrimaryNode(
              int[] rootPrimaryIndexes, int length, long[] nodes, long p) {
          if(length == 0) { return ~0; }
          int start = 0;
          int limit = length;
          for (;;) {
              int i = (int)(((long)start + (long)limit) / 2);
              long node = nodes[rootPrimaryIndexes[i]];
              long nodePrimary = node >>> 32;  // weight32FromNode(node)
              if (p == nodePrimary) {
                  return i;
              } else if (p < nodePrimary) {
                  if (i == start) {
                      return ~start;  // insert s before i
                  }
                  limit = i;
              } else {
                  if (i == start) {
                      return ~(start + 1);  // insert s after i
                  }
                  start = i;
              }
          }
      }
docs: Like Java Collections.binarySearch(List, key, Comparator).
  
  @return the index>=0 where the item was found,
  or the index<0 for inserting the string at ~index in sorted order
  (index into rootPrimaryIndexes)