mayah / tinytoml

A header only C++11 library for parsing TOML
BSD 2-Clause "Simplified" License
167 stars 31 forks source link

unordered_map instead of map for tables? #21

Open iamwired opened 7 years ago

iamwired commented 7 years ago

Hi,

As TOML v0.4.0 specify that "Key/value pairs within tables are not guaranteed to be in any specific order.", wouldn't be better if tinytoml represented tables internally using std;;unordered_map instead of std::map?

Thanks.

mayah commented 7 years ago

Hi, since this library is not focusing on performance but handiness, I believe either is OK. But yeah, std::unordered_map seems natural for this case.

veeg commented 7 years ago

Since I rely upon writing toml tables as well as parsing them, I would rather have them outputted in insertion order than random order.

mayah commented 7 years ago

@veeg yeah, it is also reasonable. However, to keep insertion order, we need to introduce something like LinkedHashMap in Java, however it's not available in STL. Another option is to use std::vector<std::pair<std::string, Value>>> for Table, but it won't be what we want to use.

mayah commented 7 years ago

Anyway, insertion order cannot be kept without introducing a bit fancy data structure.

veeg commented 7 years ago

Ahh, I'm quite forgetfull. I played around with insertion order on my local fork instead. I must have mixed up my experiences and memories regarding the matter.

iamwired commented 7 years ago

To reduce the impact, a solution could be to limit the use of std::unordered_map to the parser? This way, the writer (that we are not using), would be unaffected. I understand it may be harder to implement though, as some code/definitions couldn't any more be shared between the two components of the library.