Hi everybody,
I've just released a class that implements a lexical trie. From the documentation:
I found a website that describes it fairly well. It provides an implementation in C and an "older" (sic) one in C++. I don't know what features the interface has; I don't think it has things like regular expressions and so forth. In any case I just thought the page was interesting to explain what a trie is:
http://linux.thai.net/~thep/datrie/datrie.html
The graph should show fairly clearly what a trie looks like in memory.
In brief, the advantage to a trie is that it stores a list of words with a look-up time proportional not to the number of words, but to the length of the word you're looking up. Contrast with a binary search array which has log(n) time, where n is the number of words -- if you have 2^12 (=4096) words, you will need -- in the worst case -- 12 steps to look up any word. In a trie, looking up 'hello' will cost you 5 steps.
Furthermore, the way a trie is structured makes it very easy (and efficient) to do things like prefix matching or regular expression matching. If you had a sorted array, this would be much more complicated; for regular expressions in particular it would be much less efficient to find all matches.
Anyhow, it's late, I'm tired, so enough of all that. :-) Without further ado, here is the website with a download link:
http://david.the-haleys.org/index.php?page=lexical-trie
Please note that the provided license:
http://david.the-haleys.org/dev/lexical-trie/LICENSE
does not allow the trie to be used in commercial applications without my permission.
I hereby give permission to Gammon Software Solutions (and/or Nick Gammon, as appropriate) to use my lexical trie class in his commercial software products, including but not limited to the MUSHclient application, at no fee or cost.
But, it would be nice -- but not required! -- to have any eventual enhancements fed back to my source code. :-)
I've just released a class that implements a lexical trie. From the documentation:
Quote:
A trie is a tree-like data structure to store words, where each branch of the tree is tagged with a letter and indicates the addition of that vector. At tree nodes, a boolean flag indicates if the word up to that point is in fact contained in the trie.
A trie is a tree-like data structure to store words, where each branch of the tree is tagged with a letter and indicates the addition of that vector. At tree nodes, a boolean flag indicates if the word up to that point is in fact contained in the trie.
I found a website that describes it fairly well. It provides an implementation in C and an "older" (sic) one in C++. I don't know what features the interface has; I don't think it has things like regular expressions and so forth. In any case I just thought the page was interesting to explain what a trie is:
http://linux.thai.net/~thep/datrie/datrie.html
The graph should show fairly clearly what a trie looks like in memory.
In brief, the advantage to a trie is that it stores a list of words with a look-up time proportional not to the number of words, but to the length of the word you're looking up. Contrast with a binary search array which has log(n) time, where n is the number of words -- if you have 2^12 (=4096) words, you will need -- in the worst case -- 12 steps to look up any word. In a trie, looking up 'hello' will cost you 5 steps.
Furthermore, the way a trie is structured makes it very easy (and efficient) to do things like prefix matching or regular expression matching. If you had a sorted array, this would be much more complicated; for regular expressions in particular it would be much less efficient to find all matches.
Anyhow, it's late, I'm tired, so enough of all that. :-) Without further ado, here is the website with a download link:
http://david.the-haleys.org/index.php?page=lexical-trie
Please note that the provided license:
http://david.the-haleys.org/dev/lexical-trie/LICENSE
does not allow the trie to be used in commercial applications without my permission.
I hereby give permission to Gammon Software Solutions (and/or Nick Gammon, as appropriate) to use my lexical trie class in his commercial software products, including but not limited to the MUSHclient application, at no fee or cost.
But, it would be nice -- but not required! -- to have any eventual enhancements fed back to my source code. :-)