Esempio n. 1
0
// ****************************************************************************
unsigned long cHashedString::CalculateHash(const cString & strIdent)
{
	if(strIdent.IsEmpty())
	{
		return 0;
	}
	// largest prime smaller than 65536
	unsigned long lBASE = 65521L;
	
	// lMAX is the largest n such that // 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
	unsigned int lMAX = 5522;

	unsigned int s1 = 0;
	unsigned int s2 = 0;

	int i = 0;
	unsigned int length = strIdent.GetLength();
	while(length > 0)
	{
		int k = length < lMAX ? length : lMAX;
		length -= k;
		while(--k >= 0)
		{
			s1 += (unsigned int)(tolower(strIdent[i++]) & 0XFF);
			s2 += s1;
		}
		s1 %= lBASE;
		s2 %= lBASE;
	}
	return ((s2 << 16) | s1);
}
Esempio n. 2
0
//  *******************************************************************************************************************
const weak_ptr<IXMLNode> cXMLNode::VAddElement(const cString & ElementName, const cString & ElementValue)
{
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());
	pNode->m_pElement = m_pDoc->NewElement(ElementName.GetData());
	pNode->m_pDoc = m_pDoc;

	if (!ElementValue.IsEmpty())
	{
		XMLText * pText = m_pDoc->NewText(ElementValue.GetData());
		pNode->m_pElement->InsertEndChild(pText);
	}

	m_pElement->LinkEndChild(pNode->m_pElement);
	m_ChildNodes.push_back(pNode);
	return pNode;
}
Esempio n. 3
0
//  *******************************************************************************************************************
const shared_ptr<IXMLNode> cXMLNode::InitializeForSave(const cString & RootName, const cString & StyleSheetPath)
{
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());
	pNode->m_pDoc = shared_ptr<XMLDocument>(DEBUG_NEW XMLDocument());

	pNode->m_pDoc->InsertEndChild(pNode->m_pDoc->NewDeclaration(NULL));

	if (!StyleSheetPath.IsEmpty())
	{
		cString str = "xml-stylesheet type=\"text/xsl\" href=\"" + StyleSheetPath + "\"";
		pNode->m_pDoc->InsertEndChild(pNode->m_pDoc->NewDeclaration(str.GetData()));
	}
	pNode->m_pElement = pNode->m_pDoc->NewElement(RootName.GetData());  
	pNode->m_pDoc->InsertEndChild(pNode->m_pElement);

	return pNode;
}
Esempio n. 4
0
//  *******************************************************************************************************************
uint64 cHashedString::CalculateChecksum(const cString & str)
{
	if (str.IsEmpty())
	{
		return 0;
	}
#if 0  // use simple checksum. Keeping this for reference purpose
	// largest prime smaller than 65536
	UINT64 MOD_ADLER = 65521L;

	// MAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
	unsigned int MAX_LENGTH = 5522;

	unsigned int s1 = 1;
	unsigned int s2 = 0;

	unsigned int length = str.GetLength();

	while(length > 0)
	{
		int k = length < MAX_LENGTH ? length : MAX_LENGTH;
		length -= k;
		for(int index = 0; index < k; index++)
		{
			s1 = (s1 + (str[index] & 0xFF)) % MOD_ADLER;
			s2 = (s2 + s1) % MOD_ADLER;
		}
	}

	return ((s2 << 16) | s1);
#else
	uint64 hash = 0;
	UINT length = str.GetLength();
	for (UINT i = 0; i < length; i++)
	{
		hash = str[i] + (hash << 6) + (hash << 16) - hash;
	}
	return hash & 0x7fffffff;
#endif
}