martinus / unordered_dense

A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion
MIT License
898 stars 72 forks source link

Working on a helper class that provides an immutable view of a table #113

Open schombert opened 6 months ago

schombert commented 6 months ago

I have found myself in a situation where I would like to serialize and deserialize one of your hash tables, and, ideally, I would like to be able to use the contents of the serialized hash table without having to reallocate memory (i.e. I want to be able to memory map the file and then just point to the data within it rather than copying out data into other containers). My design to accomplish this is the following: serialize the number of buckets + the buckets + the number of pairs in the vector + the vector of pairs. Then, when reading back the data, I load the arrays into a variant of the table class that just contains two spans (one for the buckets and one for the contents of the vector). This table variant exposes the same lookup operations but deletes any functions that would require altering the buckets / moving keys around / etc. Perhaps I could somehow recreate the buckets without serializing them, but I don't understand how the code works well enough to attempt that.

In any case, this isn't strictly a request, since it is something I am working on. Rather, I would like to know if you are interested the code for the feature (it is quite simple, however, so something that you could easily make for yourself). I guess I am really just sharing the idea in case you think it could be useful to other people.