lists.f90 Source File


This file depends on

sourcefile~~lists.f90~~EfferentGraph sourcefile~lists.f90 lists.f90 sourcefile~dynamical_list.f90 dynamical_list.f90 sourcefile~lists.f90->sourcefile~dynamical_list.f90 sourcefile~fixed_list.f90 fixed_list.f90 sourcefile~lists.f90->sourcefile~fixed_list.f90 sourcefile~kinds.f90 kinds.f90 sourcefile~lists.f90->sourcefile~kinds.f90 sourcefile~maxheap.f90 maxheap.f90 sourcefile~lists.f90->sourcefile~maxheap.f90 sourcefile~dynamical_list.f90->sourcefile~kinds.f90 sourcefile~fixed_list.f90->sourcefile~kinds.f90 sourcefile~maxheap.f90->sourcefile~kinds.f90

Files dependent on this one

sourcefile~~lists.f90~~AfferentGraph sourcefile~lists.f90 lists.f90 sourcefile~datastructs_mod.f90 datastructs_mod.f90 sourcefile~datastructs_mod.f90->sourcefile~lists.f90 sourcefile~samplers.f90 samplers.f90 sourcefile~datastructs_mod.f90->sourcefile~samplers.f90 sourcefile~rejection.f90 rejection.f90 sourcefile~rejection.f90->sourcefile~lists.f90 sourcefile~rejection_maxheap.f90 rejection_maxheap.f90 sourcefile~rejection_maxheap.f90->sourcefile~lists.f90 sourcefile~rejection_maxheap_composition.f90 rejection_maxheap_composition.f90 sourcefile~rejection_maxheap_composition.f90->sourcefile~lists.f90 sourcefile~rejection_maxheap_composition.f90->sourcefile~rejection_maxheap.f90 sourcefile~rejection_maxheap_two_classes.f90 rejection_maxheap_two_classes.f90 sourcefile~rejection_maxheap_two_classes.f90->sourcefile~lists.f90 sourcefile~rejection_maxheap_two_classes.f90->sourcefile~rejection_maxheap.f90 sourcefile~rejection_two_classes.f90 rejection_two_classes.f90 sourcefile~rejection_two_classes.f90->sourcefile~lists.f90 sourcefile~rejection_two_classes.f90->sourcefile~rejection.f90 sourcefile~samplers.f90->sourcefile~rejection.f90 sourcefile~samplers.f90->sourcefile~rejection_maxheap.f90 sourcefile~samplers.f90->sourcefile~rejection_maxheap_composition.f90 sourcefile~samplers.f90->sourcefile~rejection_maxheap_two_classes.f90 sourcefile~samplers.f90->sourcefile~rejection_two_classes.f90

Source Code

!> General module for lists and related operations
!> It imports the necessary modules for list and heap implementations
module datastructs_lists_mod
    use datastructs_kinds_mod
    use datastructs_lists_dynamical_list_mod
    use datastructs_lists_fixed_list_mod
    use datastructs_maxheap_mod
    implicit none
    private

    ! Constructors
    public :: dynamical_list, fixed_list, maxheap

    ! Derived types
    public :: dynamical_list_t, fixed_list_t, maxheap_t

    ! Operations
    public :: unique_values
    public :: new_fixed_list_pointer

contains

    !> Find unique values in a list of integers
    !> It uses the standard library sorting module
    !> The result is a list of unique integers
    function unique_values(list) result(unique)
        use stdlib_sorting, only: sort
        integer(kind=i4), intent(in) :: list(:) !! Input list of integers
        integer(kind=i4), allocatable :: unique(:) !! Output list of unique integers
        integer(kind=i4), allocatable :: sorted_list(:) !! Sorted copy of the input list
        integer(kind=i4) :: i !! Loop variable
        integer(kind=i4) :: count_unique !! Count of unique integers

        sorted_list = list

        call sort(sorted_list)

        count_unique = 1
        do i = 2, size(sorted_list)
            if (sorted_list(i) /= sorted_list(i-1)) count_unique = count_unique + 1
        end do

        ! get the unique values
        allocate(unique(count_unique))
        unique(1) = sorted_list(1)
        count_unique = 1
        do i = 2, size(sorted_list)
            if (sorted_list(i) /= sorted_list(i-1)) then
                count_unique = count_unique + 1
                unique(count_unique) = sorted_list(i)
            end if
        end do

    end function unique_values

end module datastructs_lists_mod