GithubHelp home page GithubHelp logo

arunkumar9t2 / trie Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 6.0 72 KB

A Java implementation of the Trie data structure

License: Apache License 2.0

Java 100.00%
trie tries search-trees search java java-library

trie's Introduction

Trie

A java implementation of the Prefix Trie data structure.

Introduction

Tries are map like ordered tree based data structures that provide fast searching of the order O(k) where k is the length of key. Read more about trie here.

Motivation

This was initially built to use in my Android app, T9 App Launcher to quickly search through list of installed applications and launch them.

Public APIs

Currently there are 3 public implementations that can be chosen from.

  • MapTrie: HashMap backed trie implementation.
  • SortedTrie: TreeMap backed trie implementation which returns suggestions and value is ascending sort order.
  • T9Trie: Helper implementation to store and retrieve suggestions for T9 sequence.

Example usage

Creating a simple trie and getting suggestions.

final MapTrie<String> trie = new MapTrie<>();

trie.insert("Hello", "Hello");
trie.insert("Help", "Help");
trie.insert("Has", "Has");
trie.insert("Have", "Have");
trie.insert("Had", "Had");
trie.insert("Hadn't", "Hadn't");
    
// Print to stdout
trie.print();

The above print() call would print the tree structure like this.

└── h
    ├── e
    │   └── l
    │       ├── l
    │       │   └── o'Hello
    │       └── p'Help
    └── a
        ├── s'Has
        ├── v
        │   └── e'Have
        └── d'Had
            └── n
                └── '
                    └── t'Hadn't

Now let's try to find all the words starting with ha. Remember that, by default the keys are case insensitive.

List<String> suggestions = trie.getValueSuggestions("ha");
System.out.print(suggestions.toString());

This will print [Has, Have, Had, Hadn't] to the console. The value is left untouched.

Contribution

If you are a developer and would like to contribute please consider making a pull request. I would appreciate any criticisms with regards to code or implementation in general.

License

This project is licensed under Apache 2.0 license.

trie's People

Contributors

arunkumar9t2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

trie's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.