I need help regarding a code I want to write in c++.

I want to develop a program that receives and visualizes CAN messages on a GUI. The messages in question are about 100 distinct ID's, so we're not talking about a large CAN network. I already have "Message" class that encapsulates the message data into signals.

I want to create a data structure (like an array) which contains all the message classes, and when I receive a new message from the CAN network I want to access the class with the matching ID to parse the content of the payload into it.

I currently have two options regarding the data structure containing the messages:

  • unordered map
  • a normal ordered array

On a normal ordered array I would need to search each message with a logarithmic search which would take about 6/7 comparisons, given the fact that I have around 100 distinct ID's. On the other hand, the unordered map needs to calculate the IDs hash function in order to return the correct Message index.

The question is: is it faster to calculate the hash function or to perform a logarithmic search on the array?

NOTE: data structure is constant and message id's are uint32_t