1

I have to get the values from this Chart which is in a XLS format file.

I am implementing a formula for heat of mixing but I am confused about how to handle this data(As shown above in the picture). My program will include two drop down lists from which i have to select an element from each drop down list.One from down list will be representing the values of 1st column and the other drop down list will be representing the values of the first row (As described in the Image Above). The system will have to show the value for those selected elements from the drop down list.

For example. If I want to get the value of Carbon (C) and Nitrogen (N) which is -2 from the table. I don't know the easiest way to get that specific value.How should I store this data?. i.e. Should I use Multidimensional Arrays , Link Lists, Dictionary, Database etc or any other approach.

This chart have a total of 73 rows and 73 columns.

That Chart is in an XLS format. (The picture shown above is just the small part from that chart.).

waleeds37
  • 99
  • 6

3 Answers3

2

I would use a 2-dimensional array. In C++, since you know how many rows/columns you want:

char elementValues[73][73];

Reasons why:

  1. 2d array values have the benefit of locality of reference, which means their values stored in memory are fairly close to each other. This means your accesses will be much faster since the computer does not have to do as much work.

  2. A linked list would be O(n) for this, while array access would only be O(1). The reason for this is you need to step through the entire list every time you want to find a value, whereas in an array, you could go right to the value you need.

  3. Dictionaries have additional processing in regards to hash values, key values, etc. that are not needed for this particular function.
Lawrence Aiello
  • 4,560
  • 5
  • 21
  • 35
0

Keep everything as

public Dictionary<string, Dictionary<string, double>> Data;

This way you don't need to deal with indexes, but can get results by using elements names:

var value = Data["Mg"]["B"];

And to serialize dictionary you can convert data into 2-dimentional array, by sorting elements names ascending (in your example they are sorted differently, which might be not-optimal, as you don't want to store molecular mass, etc. for each element to sort by that).

Community
  • 1
  • 1
Sinatr
  • 20,892
  • 15
  • 90
  • 319
0

From what I get is you are planning to store values on the basis of keys which itself are combination of two values.In my opinion

unordered_map<std::pair<char,char>, value_type>

could give you a good performance in insertion as well as lookup.

So, if you want two chars to form a single key then go for

unordered_map<std::pair<char,char>, value_type>.

However, if you want to index same data by multiple keys then I would suggest go for Boost.MultiIndex.

unordered_map is internally implemented in terms of hash-table.So, as far as insertion and look-up is concerned you would get a good performance.

ravi
  • 10,994
  • 1
  • 18
  • 36