klib icon indicating copy to clipboard operation
klib copied to clipboard

Add Serialization for khash map

Open dnbaker opened this issue 9 years ago • 4 comments

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 avatar Nov 06 '16 22:11 dnbaker

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

dnbaker avatar Mar 18 '17 07:03 dnbaker

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?

justinmk avatar Aug 24 '18 13:08 justinmk

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 avatar Aug 24 '18 13:08 dnbaker

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.

dnbaker avatar Aug 24 '18 20:08 dnbaker