Eh, problem is too hard to explain in a title...

Started by
4 comments, last by GameDev.net 19 years, 4 months ago
This is my problem: I'm making an .obj file reader, and I finished the vertex, texture, and normal coordinates reading and displaying. Next step is materials: there is a seperate file containing the material definitions, but the problem is: the are not numbered, but only have a name. And in the main object file, those names are used to refer to them... How can I point to the materials in the material file without too much slow-down? (I could place everything in a vector and then search the vector everytime for the right name, but that is a bit slow for me...) Greets Adriaan
Advertisement
Sounds like a job for a hashtable indexed with a string key type.
ieks! What's that alien stuff?
A hash table is a data structure that maps keys to array elements using a hash function. The hash function is a function that takes an object of the type of a key and yields an integral value, called a hash value, that is then used to index the array, usually after a modulus.

Some programming languages have standard library or direct language support for hash tables. For example, Java has the HashMap class in java.util.

For more information you might want to consult any basic book on data structure and algorithms or the NIST entry on hashtables or even the Wikipedia Hash Table entry.
Don't really understand... now that I think again... I think the system in my first post will do. Normally there aren't that much materials, and I only need to read everything once. (I use a display list if you know what that is)
Yes, just use std::map.

Instead of accessing the element with a number like a vector, you access it with anything of your choice (a std::string, a 'Player' object... anything). Just look online for the list of functions. Maps are extremely easy.

This topic is closed to new replies.

Advertisement