Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "KokkosHeader.h" 13 : 14 : namespace Moose 15 : { 16 : namespace Kokkos 17 : { 18 : namespace Utils 19 : { 20 : 21 : /** 22 : * Find a value in an array 23 : * @param target The target value to find 24 : * @param begin The pointer to the first element of the array 25 : * @param end The pointer next to the last element of the array 26 : * @returns The pointer to the target element, \p end if the target element was not found 27 : */ 28 : template <typename T> 29 : KOKKOS_INLINE_FUNCTION const T * 30 6620218 : find(const T & target, const T * const begin, const T * const end) 31 : { 32 6620218 : if (begin == end) 33 0 : return end; 34 : 35 6620218 : auto left = begin; 36 6620218 : auto right = end - 1; 37 : 38 17738957 : while (left <= right) 39 : { 40 17188867 : auto mid = left + (right - left) / 2; 41 : 42 17188867 : if (*mid == target) 43 6070128 : return mid; 44 11118739 : else if (*mid < target) 45 6536724 : left = mid + 1; 46 : else 47 4582015 : right = mid - 1; 48 : } 49 : 50 550090 : return end; 51 : } 52 : 53 : } // namespace Utils 54 : } // namespace Kokkos 55 : } // namespace Moose