• Create Account

### #ActualÁlvaro

Posted 16 November 2012 - 03:31 PM

Can this be moved to General Programming or For Beginners? It has nothing to do with graphics...

Your algorithm is broken. As long as not all strings are identical, NEW will always be true and you will end up with pNrUniqueMaterials == pNrMaterials. A correct algorithm in the style of yours would go something like this:
int pNrUniqueMaterials = 0;
for (int i = 0; i < pNrMaterials; ++i) {
if (std::find(tempTexFiles, tempTexFiles+i, tempTexFiles[i]) == tempTexFiles+i)
++pNrUniqueMaterials;
}


If you have a large number of strings and this takes too long, you can do better, for instance by using an unordered_set.

### #2Álvaro

Posted 16 November 2012 - 03:31 PM

Can this be moved to General Programming or For Beginners? It has nothing to do with graphics...

Your algorithm is broken. As long as not all strings are identical, NEW will always be true and you will end up with pNrUniqueMaterials == pNrMaterials. A correct algorithm in the style of yours would go something like this:
int pNrUniqueMaterials = 0;
for (int i = 0; i < pNrMaterials; ++i) {
if (std::find(tempTexFiles, tempTexFiles+i, tempTexFiles[i]) == tempTexFiles+i)
++pNrUniqueMaterials;
}


If you have a large number of strings and this takes too long, you can do better, for instance by using an unordered_set.

### #1Álvaro

Posted 16 November 2012 - 03:31 PM

Can this be moved to General Programming or For Beginners? It has nothing to do with graphics...

Your algorithm is broken. As long as not all strings are identical, NEW will always be true and you will end up with pNrUniqueMaterials == pNrMaterials. A correct algorithm in the style of yours would go something like this:
int n_unique_materials = 0;
for (int i = 0; i < pNrMaterials; ++i) {
if (std::find(tempTexFiles, tempTexFiles+i, tempTexFiles[i]) == tempTexFiles+i)
++pNrUniqueMaterials;
}


If you have a large number of strings and this takes too long, you can do better, for instance by using an unordered_set.

PARTNERS