https://github.com/mtchavez/trie-erl
Fredkin trie algorithm in Erlang
https://github.com/mtchavez/trie-erl
Last synced: 2 months ago
JSON representation
Fredkin trie algorithm in Erlang
- Host: GitHub
- URL: https://github.com/mtchavez/trie-erl
- Owner: mtchavez
- Created: 2013-04-13T04:14:13.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-04-17T19:47:08.000Z (about 12 years ago)
- Last Synced: 2025-02-04T15:32:42.462Z (4 months ago)
- Language: Erlang
- Size: 125 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
trie-erl
========[](https://travis-ci.org/mtchavez/trie-erl)
Fredkin trie algorithm in Erlang
## Initializing
Initialize a new tree/dictionary for the Trie.
```erlang
C("src/trie").
T = trie:init().
% {dict,0,16,16,8,80,48,
% {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
% {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
```## Inserting
Insert some values using binary lists ie. ```<<"word">>```
```erlang
c("src/trie").
T1 = trie:init().
T2 = trie:insert(<<"to">>, T1).
T3 = trie:insert(<<"tea">>, T2).dict:fetch_keys(T3).
% [<<"t">>]dict:fetch_keys( dict:fetch(<<"t">>, T3) ).
% [<<"e">>,<<"o">>]
```## Finding
Using the same tree ```T3``` from the inserting example you can find as so
```erlang
% Found
trie:find(<<"tea">>, T3).
% {ok, <<"tea">>}% Not Found
trie:find(<<"asdf">>, T3).
$ {notfound, <<"asdf">>}
```## Tests
Run using ```make test``` or ```rebar eunit```
## License
Written by Chavez
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php