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

Functions

template<typename ForwardIterator , typename T >
bool bolt::amp::binary_search (bolt::amp::control &ctl, ForwardIterator first, ForwardIterator last, const T &value)
 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::amp::binary_search (ForwardIterator first, ForwardIterator last, const T &value)
 
template<typename ForwardIterator , typename T , typename StrictWeakOrdering >
bool bolt::amp::binary_search (bolt::amp::control &ctl, ForwardIterator first, ForwardIterator last, const T &value, StrictWeakOrdering comp)
 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::amp::binary_search (ForwardIterator first, ForwardIterator last, const T &value, StrictWeakOrdering comp)
 

Detailed Description

Function Documentation

template<typename ForwardIterator , typename T >
bool bolt::amp::binary_search ( bolt::amp::control ctl,
ForwardIterator  first,
ForwardIterator  last,
const T &  value 
)

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 accelerator, debug, tuning, etc.See bolt::amp::control.
firstThe first position in the sequence to search.
lastThe last position in the sequence to search.
valueThe value to search.
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/amp/sort.h>
int a[8] = {2, 9, 3, 7, 5, 6, 3, 8};
// for arranging the elements in ascending order
bolt::amp::sort( a, a+8 );
int val = a[2];
bolt::amp::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::amp::binary_search ( bolt::amp::control ctl,
ForwardIterator  first,
ForwardIterator  last,
const T &  value,
StrictWeakOrdering  comp 
)

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 accelerator, debug, tuning, etc.See bolt::amp::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.
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/amp/sort.h>
int a[8] = {2, 9, 3, 7, 5, 6, 3, 8};
// for arranging the elements in descending order
bolt::amp::sort( a, a+8, bolt::camp::greater<int>());
int val = a[2];
See Also
http://www.sgi.com/tech/stl/binary_search.html