Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to insert new node? #74

Open
ArlanCooper opened this issue Sep 24, 2021 · 4 comments
Open

how to insert new node? #74

ArlanCooper opened this issue Sep 24, 2021 · 4 comments

Comments

@ArlanCooper
Copy link

if i want to insert new nodes,how can i insert into the trie?
i can't find the methord of insert or add in the class?

@wyk201722
Copy link

Found a way to update the trie tree node
We could find the way to initailize the trie tree is adding a list of words to the marisa_trie.Trie
Just appending the new node(word) to the list, and update trie. This is how it works for me

if i want to insert new nodes,how can i insert into the trie? i can't find the methord of insert or add in the class?

@BoboTiG
Copy link
Contributor

BoboTiG commented Aug 9, 2022

@wyk201722 would you mind providing a minimal code 🙏 ?

@wyk201722
Copy link

No sure I got what the "insert new node" mean in this question, but I tried in this way.
5
6

just attached a simple test here, there is no "balabala" in the word_list or trie initially. We appended it in to the word_list and then we "reinitialize" or "insert" the word_list with "balabala" to the trie. In the second prefix_search, we could find "balabala".

I was wondering whether the index of item in word_list would change the key value of the node in trie. Therefore, I tried another test insert another word "foo" into the second place in the word_list, and then update the trie. The result shows the key value of the node in trie is not related with the position/index of the word in word_list, but the sequence/order of word insertion.

Just modifing(insert/delete) the item in the list would update the nodes in trie. Hope this works for you.

@qixiang109
Copy link

Found a way to update the trie tree node We could find the way to initailize the trie tree is adding a list of words to the marisa_trie.Trie Just appending the new node(word) to the list, and update trie. This is how it works for me

if i want to insert new nodes,how can i insert into the trie? i can't find the methord of insert or add in the class?

maybe not the best way. We need marisa-trie mostly because we can not afford for the memory usage of a keeping plain list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants