Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnjansen/ternary_search_tree
A Crystal implementation of a Ternary Search Tree
https://github.com/johnjansen/ternary_search_tree
crystal datastructure tree
Last synced: about 1 month ago
JSON representation
A Crystal implementation of a Ternary Search Tree
- Host: GitHub
- URL: https://github.com/johnjansen/ternary_search_tree
- Owner: johnjansen
- License: mit
- Created: 2017-06-30T19:32:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-07T04:02:50.000Z (over 7 years ago)
- Last Synced: 2024-06-21T23:40:17.726Z (6 months ago)
- Topics: crystal, datastructure, tree
- Language: Crystal
- Size: 21.5 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - ternary_search_tree - Ternary Search Tree (Algorithms and Data structures)
- awesome-crystal - ternary_search_tree - Ternary Search Tree (Algorithms and Data structures)
README
# Ternary Search Tree - (pure crystal-lang)
[![GitHub version](https://badge.fury.io/gh/johnjansen%2Fternary_search_tree.svg)](http://badge.fury.io/gh/johnjansen%2Fternary_search_tree)
[![CI](https://travis-ci.org/johnjansen/ternary_search_tree.svg?branch=master)](https://travis-ci.org/johnjansen/ternary_search_tree)In computer science, a ternary search tree is a type of trie (sometimes called a prefix tree) where nodes are arranged in a manner similar to a binary search tree, but with up to three children rather than the binary tree's limit of two. Like other prefix trees, a ternary search tree can be used as an associative map structure with the ability for incremental string search. However, ternary search trees are more space efficient compared to standard prefix trees, at the cost of speed. Common applications for ternary search trees include spell-checking and auto-completion. (wikipedia)
Furthur considerations from [Hackthology](http://hackthology.com/ternary-search-tries-for-fast-flexible-string-search-part-1.html)
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
ternary_search:
github: johnjansen/ternary_search
```## Usage
```crystal
require "ternary_search"tst = TernarySearch::Tree.new
# add to the TST
tst.insert("polygon") # => nil
tst.insert("triangle") # => nil# search the TST
tst.search("polygon") # => true
tst.search("poly") # => false
tst.search("triangle") # => true# get the max word length
tst.max_word_length # => 8# get an array of words in the TST
# DO NOT USE THIS ON LARGE TST's
# i'm looking into a block version of this!
tst.words = ["polygon", "triangle"]
```## Contributing
1. Fork it ( https://github.com/johnjansen/ternary_search/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request## Contributors
- [johnjansen](https://github.com/johnjansen) John Jansen - creator, maintainer
- [RX14](https://github.com/RX14) Chris Hobbs - rewriter, maintainer