Module osl_combination

module osl_combination

    ! Uses
    use osl_core, wp => osl_wp
    use osl_special, only: osl_choose

    ! Subroutines and functions
    public subroutine osl_combination_first(c)
    public function osl_combination_valid(c, n)
    public function osl_combination_rank(c, n)
    public subroutine osl_combination_unrank(rank, n, c)
    public subroutine osl_combination_next(n, c, status)
    public function osl_combination_count(n, k)

end module osl_combination

Description of Subroutines and Functions

osl_combination_first

public subroutine osl_combination_first(c)
    integer, dimension(:), intent(out) :: c
end subroutine osl_combination_first

Return the first combination in colex order.

osl_combination_valid

public function osl_combination_valid(c, n)
    integer, dimension(:), intent(in) :: c
    integer, intent(in) :: n
    logical :: osl_combination_valid
end function osl_combination_valid

Return .TRUE. if C is a valid combination in colex form and .FALSE. otherwise.

osl_combination_rank

public function osl_combination_rank(c, n)
    integer, dimension(:), intent(in) :: c
    integer, intent(in) :: n
    integer :: osl_combination_rank
    ! Calls: osl_error
end function osl_combination_rank

Return the colex rank ordering of a given combination C. This is an implementation of algorithm Algorithm 5 of Stanton and White (1986).

osl_combination_unrank

public subroutine osl_combination_unrank(rank, n, c)
    integer, intent(in) :: rank
    integer, intent(in) :: n
    integer, dimension(:), intent(out) :: c
end subroutine osl_combination_unrank

Return the combination of the given colex RANK and range N in C. This is an implementation of algorithm Algorithm 6 of Stanton and White (1986).

osl_combination_next

public subroutine osl_combination_next(n, c, status)
    integer, intent(in) :: n
    integer, dimension(:), intent(inout) :: c
    integer, optional, intent(out) :: status
    ! Calls: osl_combination_first, osl_error
end subroutine osl_combination_next

Return the next combination in colex order. This is an adaptation of algorithm Algorithm 4 of Stanton and White (1986).

osl_combination_count

public function osl_combination_count(n, k)
    integer, intent(in) :: n
    integer, intent(in) :: k
    integer :: osl_combination_count
end function osl_combination_count

Return the number of combinations of range N and size K.