Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chouffe/clj-trie
Trie implementation in Clojure
https://github.com/chouffe/clj-trie
autocompletion clj-trie clojure trie
Last synced: about 7 hours ago
JSON representation
Trie implementation in Clojure
- Host: GitHub
- URL: https://github.com/chouffe/clj-trie
- Owner: Chouffe
- License: epl-1.0
- Created: 2016-01-14T18:16:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-02T01:33:31.000Z (over 8 years ago)
- Last Synced: 2024-08-09T21:47:57.330Z (3 months ago)
- Topics: autocompletion, clj-trie, clojure, trie
- Language: Clojure
- Size: 10.7 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# clj-trie
A Clojure library designed to implement [tries](https://en.wikipedia.org/wiki/Trie).
A trie is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings.## Usage
Tries are interesting datastructures. Here is a list of potential applications:
1. As a replacement of other Data Structures - Hash Table / Binary Search Tree
* Lookups in a trie is faster in the worst case, O(m) time, compared to an imperfect hash table
* No collisions of different keys
* No hash function needed
* Can provide alphabetical ordering of the entries by key
2. Dictionary representationA common application is storing a set of words in the trie. A trie is then able to quickly search for, insert and delete entries. Tries are often use in spell checking or autocompletion systems.
## Get Started
### Inserts
```
(trie ["doo" "foo" "doa" "foot"])
(into (trie) ["doo" "foo" "doa" "foot"])
(conj (trie) "doo")
```### Lookups
```
(let [t (trie ["doo" "foo" "doa" "foot"])]
(get t "doo") ; => "doo"
(get t "boo") ; => nil
)
```### Autocompletion
```
(let [t (trie ["doo" "foo" "doa" "foot"])]
(t "do") ; => ["doa", "doo"]
(t "boo") ; => nil
(t "f") ; => ["foo", "foot"]
)```
## TestsProperty testing is used for testing the trie implementation.
To run the tests:```
lein repl
(in-ns 'trie.core)
(use 'clojure.test)
(run-tests)
```## License
Copyright © 2016 Arthur Caillau
Distributed under The MIT License (MIT)