Added const binary search method to array along with warning: it will use linear_search if the array is not sorted
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2588 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
c0817da71c
commit
af7cd5395c
|
@ -378,7 +378,8 @@ public:
|
|||
|
||||
//! Performs a binary search for an element, returns -1 if not found.
|
||||
/** The array will be sorted before the binary search if it is not
|
||||
already sorted.
|
||||
already sorted. Caution is advised! Be careful not to call this on
|
||||
unsorted const arrays, or the slower method will be used.
|
||||
\param element Element to search for.
|
||||
\return Position of the searched element if it was found,
|
||||
otherwise -1 is returned. */
|
||||
|
@ -389,6 +390,21 @@ public:
|
|||
}
|
||||
|
||||
|
||||
//! Performs a binary search for an element if possible, returns -1 if not found.
|
||||
/** This method is for const arrays and so cannot call sort(), if the array is
|
||||
not sorted then linear_search will be used instead. Potentially very slow!
|
||||
\param element Element to search for.
|
||||
\return Position of the searched element if it was found,
|
||||
otherwise -1 is returned. */
|
||||
s32 binary_search(const T& element) const
|
||||
{
|
||||
if (is_sorted)
|
||||
return binary_search(element, 0, used-1);
|
||||
else
|
||||
return linear_search(element);
|
||||
}
|
||||
|
||||
|
||||
//! Performs a binary search for an element, returns -1 if not found.
|
||||
/** \param element: Element to search for.
|
||||
\param left First left index
|
||||
|
|
Loading…
Reference in New Issue