Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trie implementation [closed]

Is there any speed- and cache-efficient implementations of trie in C/C++? I know what a trie is, but I don't want reinvent the wheel, implementing it myself.

like image 946
Anton Kazennikov Avatar asked Jun 24 '09 05:06

Anton Kazennikov


People also ask

How is a trie implemented?

Implementation of Trie Insertion proceeds by walking the Trie according to the string to be inserted, then appending new nodes for the suffix of the string that is not contained in the Trie.

How do you store a trie?

Trie DB is the persistent storage. Two options are available to store the data: Document store: Since a new trie is built weekly, we can periodically take a snapshot of it, serialize it, and store the serialized data in the database. Document stores like MongoDB [4] are good fits for serialized data.

Is there a trie in C++?

This post covers the C++ implementation of the Trie data structure, which supports insertion, deletion, and search operations. We know that Trie is a tree-based data structure used for efficient retrieval of a key in a huge set of strings.

Is there STL for trie?

The so-called trie data structure poses an interesting way to store data in an easily searchable manner. When segmenting sentences of text into lists of words, it is often possible to combine the first few words that some sentences have in common.


2 Answers

if you are looking for an ANSI C implementation you can "steal" it from FreeBSD. The file you are looking for is called radix.c. It's used for managing routing data in kernel.

like image 156
SashaN Avatar answered Oct 06 '22 20:10

SashaN


I realize the question was about ready implementations, but for reference...

Before you jump on Judy you should have read "A Performance Comparison of Judy to Hash Tables". Then googling the title will likely give you a lifetime of discussion and rebutals to read.

The one explicitly cache-conscious trie I know of is the HAT-trie.

The HAT-trie, when implemented correctly, is very cool. However, for prefix search you need a sorting step on the hash buckets, which somewhat clashes with the idea of a prefix structure.

A somewhat simpler trie is the burst-trie which essentially gives you an interpolation between a standard tree of some sort (like a BST) and a trie. I like it conceptually and it's much easier to implement.

like image 20
eloj Avatar answered Oct 06 '22 18:10

eloj