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

Add Serialization for khash map #76

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Add Serialization for khash map #76

wants to merge 27 commits into from

Conversation

dnbaker
Copy link
Contributor

@dnbaker dnbaker commented Nov 6, 2016

I've tested this on a map with 4096 keys, and kh_exist, kh_key, and kh_val all agreed between original and loaded maps. This only works, however, with maps, not sets.

@dnbaker dnbaker changed the title Add Serialization Add Serialization for khash map Nov 7, 2016
@dnbaker
Copy link
Contributor Author

dnbaker commented Mar 18, 2017

I've updated this to work for sets as well as maps.

@justinmk
Copy link

justinmk commented Aug 24, 2018

It looks like this is writing bits to a file in a specific order, not "stringifying" the khash contents. (In case anyone else was wondering.)

Also, why write to a filepath instead of a caller-supplied buffer?

@@ -263,6 +309,30 @@ static inline int kputl(long c, kstring_t *s)
return 0;
}


static inline int kputl_(long c, kstring_t *s)
Copy link

@justinmk justinmk Aug 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates a lot of code and it's not clear how it's related to the serialization.

kputl could call kputl_.

Copy link
Contributor Author

@dnbaker dnbaker Aug 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to serialization. I added this so that I'd have the option of integer formatting routines which did not null-terminate for cases where I knew I would be appending to the string further. I can separate that out from this pull request later if requested. Compare kputw and kputw_ which were already present, for example. I'm not quite sure I understand why only some types were provided separate functions.

@dnbaker
Copy link
Contributor Author

dnbaker commented Aug 24, 2018

That's a reasonable point. I think having separate write (for writing to a buffer) and serialize methods (for writing to a file) where the latter calls the former is probably best. This also does not work for string sets or maps, but external storage complicates things.

@dnbaker
Copy link
Contributor Author

dnbaker commented Aug 24, 2018

I've updated this. kh_read_##name and kh_write_##name both work on FILE *s, while kh_serialize_##name and kh_deserialize_##name operate on paths.

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

Successfully merging this pull request may close these issues.

2 participants