btree_node_find_gt_pos_i8_dp2d Subroutine

private subroutine btree_node_find_gt_pos_i8_dp2d(keys, key, position, filled)

Arguments

Type IntentOptional Attributes Name
integer(kind=keyt), DIMENSION(:) :: keys
integer(kind=keyt), intent(in) :: key
integer, intent(out) :: position
integer, intent(in) :: filled

Source Code

      SUBROUTINE btree_node_find_gt_pos_i8_dp2d (keys, key, position, filled)
         INTEGER(KIND=keyt), DIMENSION(:) :: keys
         INTEGER(KIND=keyt), INTENT(IN) :: key
         INTEGER, INTENT(OUT) :: position
         INTEGER, INTENT(IN) :: filled
         INTEGER :: left, right
         !
         IF (keys(1) .GT. key) THEN
            position = 1
            RETURN
         END IF
         IF (keys(filled) .LE. key) THEN
            position = filled + 1
            RETURN
         END IF
         left = 2
         right = filled
         position = MAX(ISHFT(left + right, -1), left)
         DO WHILE (left .LE. right)
            IF (keys(position) .GT. key .AND. keys(position - 1) .LE. key) THEN
               RETURN
            END IF
            IF (keys(position) .GT. key) right = MIN(position, right - 1)
            IF (keys(position) .LE. key) left = MAX(position, left + 1)
            position = MAX(ISHFT(left + right, -1), left)
         END DO
      END SUBROUTINE btree_node_find_gt_pos_i8_dp2d