[Picojson] Let the key of objects in json be ordered by default - #16863
Merged
tqchen merged 1 commit intoApr 10, 2024
Merged
Conversation
Ubospica
force-pushed
the
main-dev/2024-04-10-picojson-order-update
branch
3 times, most recently
from
April 9, 2024 17:05
0aa1b19 to
622a54d
Compare
tqchen
reviewed
Apr 9, 2024
Ubospica
force-pushed
the
main-dev/2024-04-10-picojson-order-update
branch
3 times, most recently
from
April 9, 2024 19:37
0ee5357 to
c0f8f9a
Compare
Previously picojson define `object` as an alias of `std::unordered_map`. That means when parsing json, the order of keys in objects are uncertain and dependent on implementation. This makes it inconvenient for certain applications, e.g. in LLM generation output, we wish the order of keys the same as the order in the json file. This PR implements a ordered hashmap `ordered_hashmap` that 1) maintains the order in which the elements are inserted, and 2) have the same interface as `std::unordered_map`. Picojson will define object as an alias of `ordered_hashmap`, so the order of the input json is maintained when parsing. Macro `PICOJSON_USE_ORDERED_OBJECT` controls whether object uses the ordered version or the unordered version. It is set by default.
Ubospica
force-pushed
the
main-dev/2024-04-10-picojson-order-update
branch
from
April 9, 2024 19:40
c0f8f9a to
1d7c33b
Compare
tqchen
approved these changes
Apr 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously picojson define
objectas an alias ofstd::unordered_map. That means when parsing json, the order of keys in objects are uncertain and dependent on implementation. This makes it inconvenient for certain applications, e.g. in LLM generation output, we wish the order of keys the same as the order in the json file.This PR implements a ordered hashmap
ordered_hashmapthat 1) maintains the order in which the elements are inserted, and 2) have the same interface asstd::unordered_map. Picojson will define object as an alias ofordered_hashmap, so the order of the input json is maintained when parsing.Macro
PICOJSON_USE_ORDERED_OBJECTcontrols whether object uses the ordered version or the unordered version. It is set by default.