Pergunta

Just a quick question about the inner workings of yaml-cpp.

I noticed that when i tried to look up a key that didn't exist i got an error such as:

yaml-cpp: error at line 0, column 0: bad conversion

I was suprised by this because I would have assumed by this point post loading we would be operating directly off an in memory map

If i do lookup such as

string foo = myyaml["bar"]["foo"].as<string>();

Does that happen as efficiently as if I had a strongly typed map. Would it be more efficient if I preprocess the things i know to exist in the yaml into a c++ map and access them directly rather than via the node?

I guess i'm asking if the perf of a map is faster than acessing a node

Thanks

Foi útil?

Solução

Lookup in a map in yaml-cpp is O(n) - it loops through all entries in the map. See this issue on the project page.

Lookup in std::map is O(log n) - it stores keys in order, and binary searches to find your key. So if you have a large number of keys, it might be faster to preprocess your data. But you should probably measure first :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top