tinytoml
tinytoml copied to clipboard
unordered_map instead of map for tables?
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.
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.
Since I rely upon writing toml tables as well as parsing them, I would rather have them outputted in insertion order than random order.
@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.
Anyway, insertion order cannot be kept without introducing a bit fancy data structure.
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.
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.