btree_node_find_gte_pos_i8_sp2d Subroutine

private subroutine btree_node_find_gte_pos_i8_sp2d(keys, key, position, filled, first)

Arguments

TypeIntentOptionalAttributesName
integer(kind=keyt), DIMENSION(:):: keys
integer(kind=keyt), intent(in) :: key
integer, intent(out) :: position
integer, intent(in) :: filled
integer, intent(in), optional :: first

Contents


Source Code

      SUBROUTINE btree_node_find_gte_pos_i8_sp2d (keys, key, position, filled, first)
         INTEGER(KIND=keyt), DIMENSION(:) :: keys
         INTEGER(KIND=keyt), INTENT(IN) :: key
         INTEGER, INTENT(OUT) :: position
         INTEGER, INTENT(IN) :: filled
         INTEGER, INTENT(IN), OPTIONAL :: first
         INTEGER :: left, right, one
         !
         one = 1
         IF (PRESENT(FIRST)) one = first
         IF (one .LE. filled) THEN
            IF (keys(one) .GT. key) THEN
               position = one
               RETURN
            END IF
         END IF
         IF (keys(filled) .LE. key) THEN
            position = filled + 1
            RETURN
         END IF
         left = one + 1
         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_gte_pos_i8_sp2d