ARTEMIS
UpperBound.H
Go to the documentation of this file.
1 /* Copyright 2022 Luca Fedeli
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_
9 #define WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_
10 
11 #include <AMReX_Extension.H>
12 #include <AMReX_GpuQualifiers.H>
13 
14 namespace utils::algorithms
15 {
16 
25  template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
26  const T* upper_bound(const T* first, const T* last, const T& val)
27  {
28  const T* it;
29  size_t count, step;
30  count = last-first;
31  while(count>0){
32  it = first;
33  step = count/2;
34  it += step;
35  if (!(val<*it)){
36  first = ++it;
37  count -= step + 1;
38  }
39  else{
40  count = step;
41  }
42  }
43 
44  return first;
45  }
46 
47 }
48 
49 #endif //WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_DEVICE
int count
Definition: run_alltests.py:322
Definition: IsIn.H:16
AMREX_GPU_DEVICE AMREX_FORCE_INLINE const T * upper_bound(const T *first, const T *last, const T &val)
Returns a pointer to the first element in the range [first, last) that is greater than val.
Definition: UpperBound.H:26