Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя pritishn

Автор pritishn, 6 лет назад, По-английски

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?

  • Проголосовать: нравится
  • +51
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +39 Проголосовать: не нравится

There is no one short or even one correct answer google for serialization. Something like this.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

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

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +16 Проголосовать: не нравится

For serializing trie in C++ this may help

Credits: kartik8800

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

use https://github.com/tlwg/libdatrie (or its bindings) if possible. There are builtin methods for trie serialization/deserialization