private int getIndexByKey(String key) {

    if (memberNum == 0 || key.compareTo(getKeyByIndex(0)) <= 0) {
      return 0;
    } else if (key.compareTo(getKeyByIndex(memberNum - 1)) >= 0) {
      return memberNum;
    }

    int head = 0;
    int tail = memberNum - 1;

    int pivot = 0;
    String pk;
    while (head != tail) {
      pivot = (head + tail) / 2;
      pk = getKeyByIndex(pivot);
      if (key.compareTo(pk) == 0) {
        return pivot;
      }

      if (key.compareTo(pk) > 0) {
        head = pivot;
      } else {
        tail = pivot;
      }

      if (head == tail - 1) {
        // notice that getKey(tail) always greater than key
        return key.compareTo(getKeyByIndex(head)) <= 0 ? head : tail;
      }
    }

    return pivot;
  }
Binary search implementation.

@param key to be searched or inserted.
@return the position of the smallest key larger than or equal to the passing in.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/AliasIndexPage.java