Bolt  1.3
C++ template library with support for OpenCL
Functions
CL-search

Functions

template<typename ForwardIterator , typename T >
bool bolt::cl::binary_search (bolt::cl::control &ctl, ForwardIterator first, ForwardIterator last, const T &value, const std::string &cl_code="")
 This version of binary search returns true if the search value is present within the given input range and false otherwise. The routine requires the elements to be arranged in ascending/descending order. It returns true iff there exists an iterator i in [first, last) such that *i < value and value < *i are both false.
 
template<typename ForwardIterator , typename T >
bool bolt::cl::binary_search (ForwardIterator first, ForwardIterator last, const T &value, const std::string &cl_code="")
 
template<typename ForwardIterator , typename T , typename StrictWeakOrdering >
bool bolt::cl::binary_search (bolt::cl::control &ctl, ForwardIterator first, ForwardIterator last, const T &value, StrictWeakOrdering comp, const std::string &cl_code="")
 This version of binary search returns true if the search value is present within the given input range and false otherwise. The routine requires the elements to be arranged in ascending/descending order. It returns true iff there exists an iterator i in [first, last) such that comp(*i, value) and comp(value, *i) are both false.
 
template<typename ForwardIterator , typename T , typename StrictWeakOrdering >
bool bolt::cl::binary_search (ForwardIterator first, ForwardIterator last, const T &value, StrictWeakOrdering comp, const std::string &cl_code="")
 

Detailed Description

Function Documentation

template<typename ForwardIterator , typename T >
bool bolt::cl::binary_search ( bolt::cl::control ctl,
ForwardIterator  first,
ForwardIterator  last,
const T &  value,
const std::string &  cl_code = "" 
)

This version of binary search returns true if the search value is present within the given input range and false otherwise. The routine requires the elements to be arranged in ascending/descending order. It returns true iff there exists an iterator i in [first, last) such that *i < value and value < *i are both false.

The binary_search operation is analogus to the std::binary_search function.

Parameters
ctlOptional Control structure to control command-queue, debug, tuning, etc. See bolt::cl::control.
firstThe first position in the sequence to search.
lastThe last position in the sequence to search.
valueThe value to search.
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code traits. This can be used for any extra cl code that is to be passed when compiling the OpenCl Kernel.
Template Parameters
ForwardIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
TThe type of the search element.
Returns
boolean value - true if search value present and false otherwise.

The following code example shows the use of binary_search on the elements in the ascending order.

#include <bolt/cl/sort.h>
int a[8] = {2, 9, 3, 7, 5, 6, 3, 8};
// for arranging the elements in ascending order
bolt::cl::sort( a, a+8 );
int val = a[2];
bolt::cl::binary_search( a, a+8 , val);
See Also
http://www.sgi.com/tech/stl/binary_search.html
template<typename ForwardIterator , typename T , typename StrictWeakOrdering >
bool bolt::cl::binary_search ( bolt::cl::control ctl,
ForwardIterator  first,
ForwardIterator  last,
const T &  value,
StrictWeakOrdering  comp,
const std::string &  cl_code = "" 
)

This version of binary search returns true if the search value is present within the given input range and false otherwise. The routine requires the elements to be arranged in ascending/descending order. It returns true iff there exists an iterator i in [first, last) such that comp(*i, value) and comp(value, *i) are both false.

The binary_search operation is analogus to the std::binary_search function.

Parameters
ctlOptional Control structure to control command-queue, debug, tuning, etc. See bolt::cl::control.
firstThe first position in the sequence to search.
lastThe last position in the sequence to search.
valueThe value to search.
compThe comparison operation used to compare two values.
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code traits. This can be used for any extra cl code that is to be passed when compiling the OpenCl Kernel.
Template Parameters
ForwardIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
TThe type of the search element.
Returns
boolean value - true if search value present and false otherwise.

The following code example shows the use of binary_search on the elements in the descending order.

#include <bolt/cl/sort.h>
int a[8] = {2, 9, 3, 7, 5, 6, 3, 8};
// for arranging the elements in descending order
bolt::cl::sort( a, a+8, bolt::cl::greater<int>());
int val = a[2];
bolt::cl::binary_search( a, a+8 , val, bolt::cl::greater<int>());
See Also
http://www.sgi.com/tech/stl/binary_search.html