#ifndef _COMMON_BINARYSEARCH_HPP_
#define _COMMON_BINARYSEARCH_HPP_
#ifndef _COMMON_ARRAY_HPP_
#include <common/array.hpp>
#endif
#ifndef _COMMON_BLOCK_HPP_
#include <common/block.hpp>
#endif

template <class T>
class BinarySearch
{
public:
	BinarySearch(Array<T> &sortedVector);
	~BinarySearch();
	WORD searchItem(const T &desiredItem,T &foundItem);
  WORD searchItem(const T &desiredItem,Block<T> &foundItems);
private:
	WORD searchItem(const T &desiredItem,T &foundItem,LONG &foundIndex);
	DWORD itemCount(void)const;
	Array<T> &mSortedVector;
  DWORD mItemCount;
};

template <class T>
inline
BinarySearch<T>::BinarySearch(Array<T> &sortedVector)
: mSortedVector(sortedVector), mItemCount(mSortedVector.size())
{
}

template <class T>
inline
BinarySearch<T>::~BinarySearch(void)
{
}

template <class T>
inline
DWORD BinarySearch<T>::itemCount(void)const
{
  return mItemCount;
}
#if defined(_MSC_VER)
#include <common/binsrch.tpp>
#endif
#endif
