unique Function

private function unique(vec) result(vec_unique)

Return only the unique values from vec. The result is also sorted by ascending value.

Arguments

Type IntentOptional Attributes Name
type(edge), intent(in), dimension(:) :: vec

Return Value type(edge), dimension(:), allocatable

only the unique elements of vec


Calls

proc~~unique~~CallsGraph proc~unique dag_module::unique proc~sort_ascending dag_module::sort_ascending proc~unique->proc~sort_ascending proc~swap dag_module::swap proc~sort_ascending->proc~swap

Source Code

    function unique(vec) result(vec_unique)

    type(edge),dimension(:),intent(in) :: vec
    type(edge),dimension(:),allocatable :: vec_unique !! only the unique elements of `vec`

    integer(ip) :: i !! counter
    integer(ip) :: n !! size of `vec`
    logical,dimension(:),allocatable :: mask !! for flagging the unique values

    n = size(vec)
    vec_unique = vec  ! make a copy
    if (n<=1) return

    ! get the unique elements by sorting the array
    ! and then excluding any that are the same as the previous element.
    call sort_ascending(vec_unique)
    allocate(mask(n)); mask(1) = .true.
    do i = 2, n
        mask(i) = (vec_unique(i)%ivertex/=vec_unique(i-1)%ivertex)
    end do
    vec_unique = pack(vec_unique, mask)

    end function unique