petewarden / c_hashmap

A simple string hashmap in C
http://petewarden.typepad.com/
Other
524 stars 206 forks source link

is possible write and read from file ? #10

Open denisdemais opened 8 years ago

a1880 commented 8 years ago

To write the whole hashmap to a file, you'd have to write your own serialization code. You could rewrite hashmap_iterate() to do that. The current version of hashmap_iterate() calls a function for every hashmap entry. The new version could add the item key as function parameter. To read the hashmap back, your own deserialization code would be needed. Does this answer your question?

denisdemais commented 8 years ago

yes, you do.

i will try save directly to disk. i will report you.

suggest #1 zlib zlib have a crc32 code do you can add additional support if defined, i.e., HAVE_ZLIB

suggest #2 change to avoid conflit with zlib from: unsigned long crc32(const unsigned char s, unsigned int len) to: static unsigned long crc32(const unsigned char s, unsigned int len)

suggest #3 static modifier can vary between compilers

suggest #4 uses of errorno and/or hashmap_strerror() i.e., at map_t hashmap_new() 'just' return NULL but can determine a cause of error

suggest #5 check if hashmap is valid before free() at void hashmap_free()