btree_delete_node_i8_zp2d Subroutine

private recursive subroutine btree_delete_node_i8_zp2d(node, pos, keys, values)

Arguments

Type IntentOptional Attributes Name
type(btree_node_i8_zp2d), POINTER :: node
integer, intent(inout), optional :: pos
integer(kind=keyt), intent(inout), optional, DIMENSION(:) :: keys
type(btree_data_zp2d), intent(inout), optional, DIMENSION(:) :: values

Source Code

      RECURSIVE SUBROUTINE btree_delete_node_i8_zp2d (node, pos, keys, values)
         TYPE(btree_node_i8_zp2d), POINTER :: node
         INTEGER, INTENT(INOUT), OPTIONAL :: pos
         INTEGER(KIND=keyt), DIMENSION(:), INTENT(INOUT), OPTIONAL :: keys
         TYPE(btree_data_zp2d), DIMENSION(:), INTENT(INOUT), OPTIONAL :: values
         !
         INTEGER :: i
         !
         IF (node%filled .GT. 0 .AND. ASSOCIATED(node%subtrees(1)%node)) THEN
            DO i = 1, node%filled + 1
               IF (PRESENT(pos)) THEN
                  CALL btree_delete_node_i8_zp2d (node%subtrees(i)%node, pos, keys, values)
               ELSE
                  CALL btree_delete_node_i8_zp2d (node%subtrees(i)%node)
               END IF
               IF (PRESENT(pos) .AND. i .LE. node%filled) THEN
                  keys(pos) = node%keys(i)
                  values(pos) = node%values(i)
                  pos = pos + 1
               END IF
            END DO
         ELSEIF (PRESENT(pos) .AND. node%filled .GT. 0) THEN
            keys(pos:pos + node%filled - 1) = node%keys(1:node%filled)
            values(pos:pos + node%filled - 1) = node%values(1:node%filled)
            pos = pos + node%filled
         END IF
         CALL btree_free_node_i8_zp2d (node)
      END SUBROUTINE btree_delete_node_i8_zp2d