I know it's slightly off-topic but I couldn't find any answers on other sites.
I was actually doing a project in which I think using a trie will be really helpful for processing the queries.
But if I keep remaking the trie everytime from scratch when I load the app then it's gonna be slow. So is there anyway I can store the contents of a trie ( wrapped in a class) into a file and load it directly everytime I need it?
I have done something like this using classes before , but we know trie needs dynamic memory allocation. So will it work if I wrap it in a class and put it in a file?
Also can anyone who has development experience tell how do people generally handle these query-based data-structures in apps? Do they rebuild it on the database everytime?
There is no one short or even one correct answer google for serialization. Something like this.
Thanks a LOT !
I didn't know it was called "serialization". The link you provided cleared my doubts, thanks a lot again!
This process is often called serialization/deserialization, or marshalling/unmarshalling.
There is no common solution, it must be implemented for each structure. Javas ObjectInputStream/ObjectOutputStream are often used to do these things in Java. I assume there are some tutorials arround covering common patterns in this field.
The more or less same can be done in C++, but the STL does not support much. For example see https://www.codeguru.com/cpp/cpp/algorithms/general/an-introduction-to-object-serialization-in-c.html
Thanks for the link. Yeah , I was also thinking of shifting to Java for this purpose. :)
While STL does not support serialization, it can be done with Boost's serialization library or with cereal
Thanks for informing about Cereal.
For serializing trie in C++ this may help
Credits: kartik8800
That's exactly what I was looking for. XD
Time to ctrl+c and ctrl+v.XD
Ah that's a wonderful library, thanks for sharing!
I'd definitely star that guy's repo :P
P.S. that noob forgot to free the memory by writing a suitable destructor smh xD
Just for the sake of completeness, if you're using Python, you can note that Python has a module called pickle for serialization of data (and this is used quite a lot in machine learning). You can read more about this here.
Thanks for the info :)
use https://github.com/tlwg/libdatrie (or its bindings) if possible. There are builtin methods for trie serialization/deserialization
Thanks for sharing :)