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]
Perform a binary search. See m_searching for more information on how to use this interface
Search for the value i in an integer vector Assumes this is sorted!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. Returns -1 if not present
Search for the value i in an integer vector Assumes this is sorted!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. Returns -1 if not present
Search for the value i in an integer vector Assumes this is sorted!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. Returns -1 if not present
Search for the value i in an integer vector Assumes this is sorted!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. Returns -1 if not present
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
interfaced with intervalSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval
interfaced with intervalSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval
interfaced with intervalSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval
interfaced with intervalSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval
Carry out a brute force search on an array for a given number. Returns -1 if the value is not found.
Interfaced with simpleSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32) | :: | this(:) | Search this vector |
|||
integer(kind=i32) | :: | val | Number to find in the vector |
Location of i in this
Interfaced with simpleSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64) | :: | this(:) | Search this vector |
|||
integer(kind=i64) | :: | val | Number to find in the vector |
Location of i in this
Interfaced with simpleSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32) | :: | this(:) | Search this vector |
|||
real(kind=r32) | :: | val | Number to find in the vector |
Location of i in this
Interfaced with simpleSearch
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64) | :: | this(:) | Search this vector |
|||
real(kind=r64) | :: | val | Number to find in the vector |
Location of i in this