code: private SourceRefRange findSourceRefRange(List<Reference> refList,
        InputId inputId) {
      checkNotNull(inputId);
  
      // TODO(bashir): We can do binary search here, but since this is fast enough
      // right now, we just do a linear search for simplicity.
      int lastBefore = -1;
      int firstAfter = refList.size();
      int index = 0;
  
      checkState(inputOrder.containsKey(inputId), inputId.getIdName());
      int sourceInputOrder = inputOrder.get(inputId);
      for (Reference ref : refList) {
        checkNotNull(ref.getInputId());
        int order = inputOrder.get(ref.getInputId());
        if (order < sourceInputOrder) {
          lastBefore = index;
        } else if (order > sourceInputOrder) {
          firstAfter = index;
          break;
        }
        index++;
      }
      return new SourceRefRange(refList, lastBefore, firstAfter);
    }
docs: Finds the range of references associated to {@code sourceName}. Note that
  even if there is no sourceName references the returned information can be
  used to decide where to insert new sourceName refs.