Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:46

0001 #include "HeterogeneousCore/CUDAUtilities/interface/cudastdAlgorithm.h"
0002 #include <algorithm>
0003 #include <iostream>
0004 #include <iterator>
0005 #include <vector>
0006 
0007 void testBinaryFind() {
0008   std::vector<int> data = {1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6};
0009 
0010   auto lower = cuda_std::lower_bound(data.begin(), data.end(), 4);
0011   auto upper = cuda_std::upper_bound(data.begin(), data.end(), 4);
0012 
0013   std::copy(lower, upper, std::ostream_iterator<int>(std::cout, " "));
0014 
0015   std::cout << '\n';
0016 
0017   // classic binary search, returning a value only if it is present
0018 
0019   data = {1, 2, 4, 6, 9, 10};
0020 
0021   auto test = [&](auto v) {
0022     auto it = cuda_std::binary_find(data.cbegin(), data.cend(), v);
0023 
0024     if (it != data.cend())
0025       std::cout << *it << " found at index " << std::distance(data.cbegin(), it) << std::endl;
0026     else
0027       std::cout << v << " non found" << std::endl;
0028   };
0029 
0030   test(4);
0031   test(5);
0032 }
0033 
0034 int main() { testBinaryFind(); }