S
xDD danke, das sieht wirklich leichter aus, das wäre meine lösung gewesen, bin gerade fertig geworden.
//------------------------------------------------------
//-----------------Slightly edited find-----------------
// TEMPLATE FUNCTION find
template<class _InIt, class _Ty>
inline
_InIt _Find_P(_InIt _First, _InIt _Last, const _Ty& _Val)
{ // find first matching _Val
//_DEBUG_RANGE(_First, _Last);
for (; _First != _Last; ++_First)
if (*(*_First) == *_Val)// only line changed ^.^
break;
return (_First);
}
template<class _InIt, class _Ty>
inline
_InIt find_p(_InIt _First, _InIt _Last, const _Ty& _Val)
{ // find first matching _Val
_ASSIGN_FROM_BASE(_First, _Find_P(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Val));// ah and the _P
return (_First);
}
//------------------------------------------------------
//------------------------------------------------------
bool CleanDuplicates( vector < wstring > * Strings ){
// returns -> Strings altered ? Y / N
// Usage : v32 = ~crc32_calc (msg, len, ~0U);
struct STRING_INFO{
explicit STRING_INFO( DWORD C, unsigned int SP ):StringPos(SP),CRC(C){
// crc's are correct.
//cout << hex << C << endl;
}
bool operator == ( STRING_INFO const& R )
{
return (this->CRC == R.CRC);
}
const DWORD CRC;
const unsigned int StringPos;
};
bool RetVal = false;
vector < STRING_INFO * > * CRC = new vector < STRING_INFO * >( Strings->size() );
for ( unsigned int i = 0; i < Strings->size(); i++ )
(*CRC)[i] = new STRING_INFO( ~crc32_calc( reinterpret_cast < const BYTE * >( (*Strings)[i].c_str() ), (*Strings)[i].size(), ~0U ), i );
for ( vector < STRING_INFO * >::iterator It = CRC->begin(); It < CRC->end(); It++ ){
vector < STRING_INFO * >::iterator Beg = CRC->begin();
vector < STRING_INFO * >::iterator Pos;
for ( ;; ){
Pos = find_p( Beg, CRC->end(), *It );
if ( Pos == CRC->end() || Pos == CRC->end() - 1)
break;// 2ter loop
if ( Pos == It ){
Beg = It + 1;
continue;// 1ster loop
}
RetVal = true;
// Relocate It
STRING_INFO * Temp = *It;
(*Strings)[(*Pos)->StringPos] = L"";
delete *Pos;
CRC->erase( Pos );
Beg = CRC->begin();
It = find_p( Beg, CRC->end(), Temp );
}
}
for ( unsigned int i = 0; i < CRC->size(); i++ )
delete (*CRC)[i];
for ( int i = 0, n = Strings->size(); i < n; i++ ){
if ( !(*Strings)[i].compare(L"") ){
Strings->erase( Strings->begin() + i );
n = Strings->size();
--i;
}
}
return RetVal;
}