/*! \file Helpers.h
	\brief Various helper functions. 

	This internal header file contains helper functions used in the various sparse set implementations. 
	It is not necessary to include this file directly anywhere outside of the sparse set implementations. 
	Nevertheless the functions described below are automatically available if one of the sparse set 
	headers is included.
	
	\sa
	- BitList.h
	- BitTree.h
	- DenseBitVector.h
	- SparseVitVector.h
	- RiceSet.h
	\sa
*/

#ifndef _Helpers_h_included_
#define _Helpers_h_included_

/*! \brief The sps (SParseSet) namespace contains all classes and functions of the SparseSet project.
*/
namespace sps
{
	/*! \brief Template function to determine the size of a type in bits.

		This little helper function returns the size of a type in bits. 
		The runtime of this function is 0, because the compiler can determine the
		result already at compile time.

		Examples:
		- sizeof_bits< char >() will return 8. 
	*/
	template < class T >
	inline size_t sizeof_bits()
	{
		return sizeof( T ) * 8;
	}

	/*! \brief Returns the binary logarithm of nValue.

		This function calculates the binary logarithm of nValue. It's an interger function 
		and will therefore not always return the accurate value but the nearest integer not 
		less than the binary logarithm of nValue. The runtime of sps::lg(n) is in O(lg(n)).

		Examples:
		- lg(8) will return 3
		- lg(5) will also return 3
		- lg(4) will return 2
	*/
	inline size_t lg( size_t nValue )
	{
		size_t nResult = 0;
		for ( ; ( 1u << nResult ) < nValue; ++nResult );
		return nResult;
	}
}

#endif //_Helpers_h_included_