Return only the unique values from vec
.
The result is also sorted by ascending value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(edge), | intent(in), | dimension(:) | :: | vec |
only the unique elements of vec
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