Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Efficient check for equivalency? #1325

Closed
JimAtCanon opened this issue Oct 27, 2018 · 2 comments
Closed

[Question] Efficient check for equivalency? #1325

JimAtCanon opened this issue Oct 27, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@JimAtCanon
Copy link

Hello All-

I have an application that is using JSON objects to store a set of parameters of different types. I refer to these objects as 'parameter bags'. When I set (change) the value of a parameter that is already in the bag, I want to also check to see if the new parameter value is different than the current value (is the value changing, the bag becomes 'dirty').

For simple types like floats and strings, I assume the check is very straight forward and efficient, however I am concerned about the efficiency of checking equivalency for arrays and parameters that themselves are JSON objects. Can anyone share with me any insight they may have concerning the best way to compare two JSON objects? IS a simple Obj1 == Obj2 the best way to go?

Thanks in advance!

Jim

@nlohmann
Copy link
Owner

JSON arrays are stored as std::vector, and JSON objects as std::map. Comparing two JSON values with operator== checks equality based on the C++ types. So, yes, applying Obj1 == Obj2 is the best way to go.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Oct 27, 2018
@JimAtCanon
Copy link
Author

Awesome, and thanks again for a great library and fantastic support, took a whole two minutes to get the answer my question!

Jim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants