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

Object's member access is O(n) #6

Closed
miloyip opened this issue Jun 6, 2014 · 4 comments
Closed

Object's member access is O(n) #6

miloyip opened this issue Jun 6, 2014 · 4 comments

Comments

@miloyip
Copy link
Collaborator

miloyip commented Jun 6, 2014

From milo...@gmail.com on November 30, 2011 13:31:34

Object member access, i.e. Value::FindMember(), is in O(n) by linear searching.

Design a faster approach for member access.

Original issue: http://code.google.com/p/rapidjson/issues/detail?id=5

@miloyip
Copy link
Collaborator Author

miloyip commented Jun 6, 2014

From fasdfas...@gmail.com on July 23, 2013 02:28:40

I don't think it is possible to use a faster algorithm without ordering the keys.

Ordering the keys and putting them in a map also has a overhead so it is does not make sense to implement it.

Users should access a value once, then store it and re-use the value without calling Document::operator []. That will be faster than anything.

@miloyip
Copy link
Collaborator Author

miloyip commented Jun 6, 2014

From bas...@starynkevitch.net on November 05, 2013 02:00:59

With C++11 it is possible to use std::unordered_map see e.g. http://en.cppreference.com/w/cpp/container/unordered_map

@miloyip
Copy link
Collaborator Author

miloyip commented Jun 6, 2014

From drawtree@gmail.com on December 20, 2013 20:57:52

Just my opinion…

AFAIK, hash-map overhead is known to be a lot heavier than sorted B-trees if key count is small. And JSON object usually expected to have a few of keys - less than 10 keys for example - because large number of keys means there's something wrong with data structure design.

So I doubt on using hash-map for performance. If your object has dozens of keys, it would make sense, but I never seen such JSON object.

IMO, binary search is the best approach for a JSON object, and C++11 std::map is usually intended to be a b-tree.

@lukeworthtkbt
Copy link

I am comparing two JSON objects, each with ~180,000 elements and operator== is really slow because of this. Just my 2¢.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants