Find the position of a specific path in the list of all paths.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_path_type), | intent(in) | :: | sPath |
Specific path to search. |
||
type(tem_path_type), | intent(in) | :: | Pathlist(:) |
List of paths for all elements to search in. |
||
integer, | intent(in), | optional | :: | lower |
Possibly only search on a subinterval, starting at PathList(lower:) |
|
integer, | intent(in), | optional | :: | upper |
Possibly only search on a subinterval, ending at PathList(:upper) |
Position where sPath is found in Pathlist
pure function tem_PosOfPath(sPath, Pathlist, lower, upper) result(IdPos) ! -------------------------------------------------------------------- ! !> Specific path to search. type(tem_path_type), intent(in) :: sPath !> List of paths for all elements to search in. type(tem_path_type), intent(in) :: Pathlist(:) !> Possibly only search on a subinterval, starting at PathList(lower:) integer, intent(in), optional :: lower !> Possibly only search on a subinterval, ending at PathList(:upper) integer, intent(in), optional :: upper !> Position where sPath is found in Pathlist integer :: IdPos ! -------------------------------------------------------------------- ! integer :: lb, ub integer :: middleSearch type(tem_path_type) :: current integer(kind=long_k) :: pathRelation integer :: maxPathLen ! -------------------------------------------------------------------- ! if (present(lower)) then lb = lower else lb = lbound(PathList,1) end if if (present(upper)) then ub = upper else ub = ubound(PathList,1) end if ! Start the Binary search for the neighbor elements binSearchLoop: do middleSearch = (lb + ub) / 2 ! Build the path to the currently investigated element from leaf to root. current = PathList(middleSearch) ! pathRelation = tem_PathComparison(sPath, current) ! Inlined tem_PathComparison: maxPathLen = min(sPath%level-1, current%level-1) pathRelation = sPath%Node(sPath%level - maxPathLen) & & - current%Node(current%level - maxPathLen) if ((pathRelation == 0_long_k) .or. (lb >= ub)) then ! Leave the loop, if element has been found, or this ! was the last element to investigate. exit binSearchLoop else halves: if (pathRelation > 0_long_k) then ! Continue the search in the higher half, as the looked up element is ! to small. lb = min(middleSearch + 1, ub) else ! Continue search in the lower half, as the looked up element is to ! large. ub = max(middleSearch - 1, lb) end if halves end if end do binSearchLoop if (pathRelation == 0_long_k) then if (current%Level <= sPath%Level) then ! The found ID is actually a leaf IdPos = middleSearch else ! The found ID is a child of the searched ! virtual treeID IdPos = -middleSearch end if else IdPos = 0 ! no matching element found. end if end function tem_PosOfPath