This class has some searching algorithm method.
More...
#include <SearchTool.h>
|
| template<typename S , typename T > |
| static int | binarySearch (S value, boost::function< T(int) > getElementFun, boost::function< int(T, S) > compareFun, int size) |
| | binary search More...
|
| |
This class has some searching algorithm method.
Definition at line 26 of file SearchTool.h.
template<typename S , typename T >
| static int kome::core::SearchTool::binarySearch |
( |
S |
value, |
|
|
boost::function< T(int) > |
getElementFun, |
|
|
boost::function< int(T, S) > |
compareFun, |
|
|
int |
size |
|
) |
| |
|
inlinestatic |
binary search
- Parameters
-
| [in] | value | specified value |
| [in] | getElementFun | function which get element from array. |
| [in] | compareFun | comparison function. return value
- more than zero : element's value is greater than specified value.
- zero: element's value is equal to specified value.
- less than zero: element's value is less than specified value.
|
| [in] | size | size of array |
- Returns
- If it contains a element which has specified value, this function returns the index. [0 or positive] Otherwise it returns (- insertion point - 1). [negative]
Definition at line 48 of file SearchTool.h.
56 int bottom = size - 1;
60 while( top <= bottom && idx < 0 ) {
62 int mid = ( top + bottom ) / 2;
63 T elm0 = getElementFun( mid );
66 int cmp = compareFun( elm0, value );
73 T elm1 = getElementFun( mid );
74 if( compareFun( elm1, value ) == 0 ) {
The documentation for this class was generated from the following file: