U
Uzytkownik
I've map<unsigned int, Class*>. I'd like to find unused ID.
Is it easier (and/or faster) code:
template<class Class>
int findID(map<unsiged int, Class*>)
{
unsigned int max;
set<unsigned int> Set;
for(map<unsigned int, Class*>::iterator it = mymap.begin(); it !=
mymap.end; it++)
{
Set.insert(it->first);
if(it->first > max)
max = it->first;
}
for(unsigned int i = 0; i <= max; i++)
if(Set.find(i) == Set.end())
return i;
return max + 1;
}
Regards.
Is it easier (and/or faster) code:
template<class Class>
int findID(map<unsiged int, Class*>)
{
unsigned int max;
set<unsigned int> Set;
for(map<unsigned int, Class*>::iterator it = mymap.begin(); it !=
mymap.end; it++)
{
Set.insert(it->first);
if(it->first > max)
max = it->first;
}
for(unsigned int i = 0; i <= max; i++)
if(Set.find(i) == Set.end())
return i;
return max + 1;
}
Regards.