m_searching Module

module~~m_searching~~UsesGraph module~m_searching m_searching module~variablekind variableKind module~variablekind->module~m_searching iso_fortran_env iso_fortran_env iso_fortran_env->module~variablekind
Help

Contains routines to perform a simple binary search on a vector

Example usage

program binarySearch_test
use variableKind, only: i32, r64
use m_BinarySearch, only: binarySearch

implicit none

real(r64) :: arr(20)
integer(i32) :: i
integer(i32) :: j
arr=[(dble(i), i = 1, 20)]
j = binarySearch(arr, 10.d0, 1, 20)
write(*,*) 'Location of 10.0 in arr is 10? ',j == 10
end program

Perform a binary search but also return the neighbouring interval if the actual value is not found. This is useful if you need to find a number that is not contained in the array and you want the interval

Example usage

use variableKind
use m_BinarySearch, only: intervalSearch
real(r64) :: arr(20)
integer(i32) :: i
integer(i32) :: j(3)
arr=[(dble(i), i = 1, 20)]
j = intervalSearch(arr, 10.5d0, 1, 20)
write(*,*) 'Location of 10.5 in arr is -1? ',j(1) == -1
write(*,*) 'The interval containing 10.5 is [10,11]? ',j(2:3) == [10,11]

Used By

module~~m_searching~~UsedByGraph module~m_searching m_searching module~idynamicarray_class iDynamicArray_Class module~m_searching->module~idynamicarray_class program~scaletest_coretran scaleTest_coretran module~m_searching->program~scaletest_coretran module~dargdynamicarray_class dArgDynamicArray_Class module~m_searching->module~dargdynamicarray_class module~iargdynamicarray_class iArgDynamicArray_Class module~m_searching->module~iargdynamicarray_class module~rargdynamicarray_class rArgDynamicArray_Class module~m_searching->module~rargdynamicarray_class module~iddynamicarray_class idDynamicArray_Class module~m_searching->module~iddynamicarray_class module~ddynamicarray_class dDynamicArray_Class module~m_searching->module~ddynamicarray_class module~rdynamicarray_class rDynamicArray_Class module~m_searching->module~rdynamicarray_class module~idargdynamicarray_class idArgDynamicArray_Class module~m_searching->module~idargdynamicarray_class module~idynamicarray_class->module~dargdynamicarray_class module~idynamicarray_class->module~iargdynamicarray_class module~idynamicarray_class->module~rargdynamicarray_class module~idynamicarray_class->module~idargdynamicarray_class module~m_kdtree m_KdTree module~idynamicarray_class->module~m_kdtree module~m_tests m_tests module~idynamicarray_class->module~m_tests module~dargdynamicarray_class->module~m_kdtree module~dargdynamicarray_class->module~m_tests module~iargdynamicarray_class->module~m_tests module~rargdynamicarray_class->module~m_tests module~iddynamicarray_class->module~idargdynamicarray_class module~iddynamicarray_class->module~m_tests module~ddynamicarray_class->module~dargdynamicarray_class module~ddynamicarray_class->module~m_tests module~rdynamicarray_class->module~rargdynamicarray_class module~rdynamicarray_class->module~m_tests module~idargdynamicarray_class->module~m_tests module~m_kdtree->program~scaletest_coretran module~m_kdtree->module~m_tests program~test_coretran test_coretran module~m_tests->program~test_coretran
Help


Interfaces

public interface binarySearch

Perform a binary search. See m_searching for more information on how to use this interface

  • public recursive function binarySearch_i1D(this, v, imin, imax) result(iout)

    Search for the value i in an integer vector Assumes this is sorted!

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)

    Vector to search within

    integer(kind=i32) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32)

    Location of i in this. Returns -1 if not present

  • public recursive function binarySearch_id1D(this, v, imin, imax) result(iout)

    Search for the value i in an integer vector Assumes this is sorted!

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)

    Vector to search within

    integer(kind=i64) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32)

    Location of i in this. Returns -1 if not present

  • public recursive function binarySearch_r1D(this, v, imin, imax) result(iout)

    Search for the value i in an integer vector Assumes this is sorted!

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)

    Vector to search within

    real(kind=r32) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32)

    Location of i in this. Returns -1 if not present

  • public recursive function binarySearch_d1D(this, v, imin, imax) result(iout)

    Search for the value i in an integer vector Assumes this is sorted!

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)

    Vector to search within

    real(kind=r64) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32)

    Location of i in this. Returns -1 if not present

public interface intervalSearch

Perform an interval search on an array Returns a length 3 integer(i32) array where the last two entries are the left and right neighbours The first entry of iout is -1 if the value is not present in the vector Assumes this is sorted!See m_searching for more information on how to use this interface

  • public recursive function intervalSearch_i1D(this, v, imin, imax) result(iout)

    interfaced with intervalSearch

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)

    Vector to search within

    integer(kind=i32) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32) (3)

    Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval

  • public recursive function intervalSearch_id1D(this, v, imin, imax) result(iout)

    interfaced with intervalSearch

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)

    Vector to search within

    integer(kind=i64) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32) (3)

    Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval

  • public recursive function intervalSearch_r1D(this, v, imin, imax) result(iout)

    interfaced with intervalSearch

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)

    Vector to search within

    real(kind=r32) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32) (3)

    Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval

  • public recursive function intervalSearch_d1D(this, v, imin, imax) result(iout)

    interfaced with intervalSearch

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)

    Vector to search within

    real(kind=r64) :: v

    Number to find in the vector

    integer(kind=i32) :: imin

    Left integer

    integer(kind=i32) :: imax

    Right integer

    Return Value integer(kind=i32) (3)

    Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval

public interface simpleSearch

Carry out a brute force search on an array for a given number. Returns -1 if the value is not found.

  • public function simpleSearch_i1D(this, val) result(iout)

    Interfaced with simpleSearch

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)

    Search this vector

    integer(kind=i32) :: val

    Number to find in the vector

    Return Value integer(kind=i32)

    Location of i in this

  • public function simpleSearch_id1D(this, val) result(iout)

    Interfaced with simpleSearch

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)

    Search this vector

    integer(kind=i64) :: val

    Number to find in the vector

    Return Value integer(kind=i32)

    Location of i in this

  • public function simpleSearch_r1D(this, val) result(iout)

    Interfaced with simpleSearch

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)

    Search this vector

    real(kind=r32) :: val

    Number to find in the vector

    Return Value integer(kind=i32)

    Location of i in this

  • public function simpleSearch_d1D(this, val) result(iout)

    Interfaced with simpleSearch

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)

    Search this vector

    real(kind=r64) :: val

    Number to find in the vector

    Return Value integer(kind=i32)

    Location of i in this