// FastMath.h: interface for the CFastMath class. // ////////////////////////////////////////////////////////////////////// #ifndef _CUSTOM_MATH_FUNCTIONS_H_ #define _CUSTOM_MATH_FUNCTIONS_H_ #include #include #include namespace Math { namespace Convert { extern const unsigned short m_FastHeToBi[0x100]; // SPX, IPX ÁÖ¼Ò °è»êÀ» À§ÇØ »ç¿ëÇÏ´Â ÇÔ¼ö inline unsigned char BiToHe(char cBin); inline void AcToHe(char *szDst, char *szSrc, int iCount); // StringÀ» °ªÀ¸·Î ¹Ù²Þ(StringÀº 0x°¡ ºÙÀº Hex stringÀÌ´Ù.) inline BYTE StrToHex08(const char *szSrc); inline WORD StrToHex16(const char *szSrc); inline DWORD StrToHex32(const char *szSrc); inline DWORD64 StrToHex64(const char *szSrc); // StringÀ» °ªÀ¸·Î ¹Ù²Þ(0x°¡ ºÙ´øÁö, ºÙÁö ¾Ê´øÁö°£¿¡ ÀüºÎ ¹Ù²Ü ¼ö ÀÖ´Ù) inline BYTE Atoc(char *szSrc); inline WORD Atos(char *szSrc); inline DWORD Atoi(char *szSrc); inline DWORD64 Atol64(char *szSrc); // °ªÀ» Hex StringÀ¸·Î ¹Ù²Þ inline void Hex08ToStr(char *szDest, BYTE hex); inline void Hex16ToStr(char *szDest, WORD hex); inline void Hex32ToStr(char *szDest, DWORD hex); inline void Hex64ToStr(char *szDest, DWORD64 hex); }; namespace Random { // ¸®ÅϰªÀº 0 ~ nExtent - 1ÀÇ ¹üÀ§¸¦ °®´Â´Ù. unsigned long ComplexRandom(int nExtent); // ºñ±³Àû ºÐÆ÷°¡ ÁÁ´Ù. }; namespace HashFunc { // ------------------------------------------------------------------------------------------------- // String-to-Hash ÇÔ¼öµé : http://www.cs.yorku.ca/~oz/hash.html ¿¡¼­ Âü°í inline unsigned long djb2Hash(const unsigned char *str); // first reported by dan bernstein inline unsigned long sdbmHash(const unsigned char *str); // this is one of the algorithms used in berkeley db inline unsigned long looseHash(const unsigned char *str); // °¡Àå °£´ÜÇÑ ÇØ½¬. ±×³É ¸ðµÎ ´õÇÔ. }; }; #include "Convert.inl" inline unsigned long Math::HashFunc::djb2Hash(const unsigned char *str) { unsigned long hash = 5381; int c; while (c = *str++) { hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ } return hash; } inline unsigned long Math::HashFunc::sdbmHash(const unsigned char *str) { unsigned long hash = 0; int c; while (c = *str++) { hash = c + (hash << 6) + (hash << 16) - hash; } return hash; } inline unsigned long Math::HashFunc::looseHash(const unsigned char *str) { unsigned int hash = 0; int c; while (c = *str++) { hash += c; } return hash; } #endif // !defined(AFX_FASTMATH_H__ED69578B_18C1_42EA_9C5E_888DC38101C2__INCLUDED_)