30 template <
class U,
class T>
class Search
54 return Hunt(value,prevIndex);
64 return Bisection(value,lowerLimit,mpData->Size());
70 template <
class U,
class T>
72 const T& value,
TIndex guessIndex)
const
76 if (guessIndex<0 || guessIndex>=n)
78 return Bisection(value);
80 bool ascending = (*mpData)[n-1] >= (*mpData)[0];
83 if ( (value >= (*mpData)[guessIndex]) == ascending)
85 if (guessIndex == n-1)
87 upperLimit = guessIndex+1;
88 while ( (value >= (*mpData)[upperLimit]) == ascending)
90 guessIndex = upperLimit;
93 if (upperLimit >= n) {
94 result=Bisection(value,guessIndex);
95 if(result==n-1)
return -1;
100 if (guessIndex==0)
return -1;
101 upperLimit = guessIndex--;
102 while ( (value < (*mpData)[guessIndex]) == ascending)
104 upperLimit = guessIndex;
106 if (inc >= upperLimit) {
107 result = Bisection(value,0,upperLimit);
108 if(result==0)
return -1;
111 guessIndex = upperLimit-inc;
114 return Bisection(value,guessIndex,upperLimit);
117 template <
class U,
class T>
119 const T& value,
TIndex lowerLimit,
TIndex upperLimit)
const
122 bool ascending = (*mpData)[mpData->Size()-1] >= (*mpData)[0];
123 while (upperLimit-lowerLimit > 1)
125 TIndex midPoint = (upperLimit+lowerLimit)>>1;
126 if ( (value >= (*mpData)[midPoint]) == ascending)
127 lowerLimit = midPoint;
129 upperLimit = midPoint;