Let's say you want to read from file and based on its content create a structure (or an array) containing multiple objects, for example:
struct {
unsigned id;
char name[16];
float price;
} *items;`
Then you want to reference to an object (some item) using the obtained name
, because that's how a user would know what to look for.
However, implementing searches that use loops will be very slow, especially if you have to loop every time you want to access an item and you need to access it all the time. Converting string to integer and then using a lookup table (sacrificing memory for performance) is a solution, but what if the name is longer than 8 bytes.
What is the fastest approach of accessing allocated structure, filled from an arbitrary file, using name identifiers (a string from the structure) ?