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

Serialization support #38

Open
kyrias opened this issue Nov 22, 2017 · 7 comments
Open

Serialization support #38

kyrias opened this issue Nov 22, 2017 · 7 comments

Comments

@kyrias
Copy link
Contributor

kyrias commented Nov 22, 2017

This crate is pretty much exactly what I could really use for a project of mine, but I'd need to easily be able to serialize it to disk in a portable way. Is there any chance of a serde serialization implementation happening?

@michaelsproul
Copy link
Owner

Yeah, it's very much on the cards! My other trie (radix_trie) has a Serde serialisation implementation that someone contributed, and we could probably copy much of the code from there.

I'm on vacation at the moment, and probably wouldn't get around to it for 2-3 weeks. Do you feel like giving it a shot in the meantime?

@kyrias
Copy link
Contributor Author

kyrias commented Nov 23, 2017

I'm not sure if I'm knowledgeable enough to do it, but I'll see if I can give it a shot this weekend. Have a nice vacation!

@kyrias
Copy link
Contributor Author

kyrias commented Nov 24, 2017

Actually seem to have got it working by copying the radix_trie serde implementation, and doing some small changes, but one problem is that the HashMap iteration order is arbitrary, so the tests are currently failing most of the time.

Would need to somehow sort the key iterator, hm.

@kyrias
Copy link
Contributor Author

kyrias commented Nov 24, 2017

Ah, I can just pass the same instance of RandomState to ::with_hasher.

Edit: Erhm, nevermind, I got confused by other issues. I blame my insomnia! Still unsure how to get a consistent test suite run for iterating over the hashmap, hm.

@kyrias
Copy link
Contributor Author

kyrias commented Nov 24, 2017

So, I worked around the HashMap iteration order problem by switching to BTreeMap. WIP serde branch is available here.

@kyrias
Copy link
Contributor Author

kyrias commented Nov 25, 2017

... And after fighting with Serde to get the deserialization implementaiton working for a few hours, I now realize that the auto-derived ones work just fine. sigh.


Edit: Is there any particular reason that HashMap is used rather than a BTreeMap btw? serde_derive can derive the implementations for the BTreeMap version of the code, but for the HashMap version of the code it chokes on the S trait bound which it doesn't know what to do with.

@michaelsproul
Copy link
Owner

The HashMap option is mostly for speed. Thanks for looking into this! I'm back from vacation now so I should have some time to look into it soon

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

No branches or pull requests

2 participants