如何为 Patricia Trie 实现移除/删除功能?
我已经部分实现了 Patricia Trie,它仍然不完整,因为它缺少用于从 Trie 中删除节点的删除/删除功能,我发现这篇文章描述了结构,它带有C++的实现,有一个删除/删除功能,但我不知道了解实施背后的想法是什么。
如何从 Trie 中删除节点并使 Trie 保持正确的状态?
I have partially implemented a Patricia Trie, it's still not complete since it lacks a delete/remove function which is used to remove nodes from the Trie, I have found this article describing the structure, which comes with an implementation in C++, there's a remove/delete function, but I can't figure out what's the idea behind the implementation.
How do I remove a node from the Trie and leave the Trie in a proper state?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近用 C 实现了 PATRICIA。为了删除一个节点,找到将 trie 向后指向受害者的 down-trie 节点(这可能是受害者节点本身。)
一旦找到,如果受害者节点不是向后引用者,则使用以下命令切换受害者它的引用者。这使得受害者接近成为“叶”节点,并且其向后引用将是其自身。那么删除就非常简单了。
I've implemented a PATRICIA in C recently. In order to remove a node, find the down-trie node which points backward up the trie to the victim (this may be the victim node itself.)
Once found, if the victim node is NOT the backward-referer, switch the victim with its referer. This puts the victim close to being a "leaf" node, and its backward reference will be to itself. The removal is very simple, then.