tinytoml icon indicating copy to clipboard operation
tinytoml copied to clipboard

unordered_map instead of map for tables?

Open iamwired opened this issue 7 years ago • 6 comments

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.

iamwired avatar Jun 06 '17 12:06 iamwired

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.

mayah avatar Jun 06 '17 12:06 mayah

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 avatar Jun 06 '17 12:06 veeg

@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 avatar Jun 06 '17 12:06 mayah

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

mayah avatar Jun 06 '17 13:06 mayah

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.

veeg avatar Jun 06 '17 13:06 veeg

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.

iamwired avatar Jun 07 '17 07:06 iamwired