Skip to content

Instantly share code, notes, and snippets.

@shamalroy
Last active April 30, 2021 06:03
Show Gist options
  • Save shamalroy/0feb2a7d881b67c32c9f to your computer and use it in GitHub Desktop.
Save shamalroy/0feb2a7d881b67c32c9f to your computer and use it in GitHub Desktop.
Patricia Trie Example
import java.util.*;
import org.apache.commons.collections4.Trie;
import org.apache.commons.collections4.trie.PatriciaTrie;
...
...
Map<String, BookInfo> library = new LinkedHashMap<>();
/* Load your regualr map with data */
library.put("To Kill a Mockingbird", new BookInfo("Harper Lee", "978-0061120084"));
libraby.put("Pride and Prejudice", new BookInfo("Jane Austen", "978-0679783268"));
libraby.put("To Kill A Warlock", new BookInfo("H.P. Mallory", "978-xxxxxxxx"));
libraby.put("To Kill For", new BookInfo("A.J. Carella", "978-xxxxxxxx"));
libraby.put("To Kill For", new BookInfo("A.J. Carella", "978-xxxxxxxx"));
...
...
/* PatriciaTrie map*/
public static Trie<String, BookInfo> librabyTrie = new PatriciaTrie<>(libraby);
/* Subset of data based on your query string "To Kill" */
SortedMap<String, BookInfo> entries = WordList.wordMapTrie.prefixMap("To Kill");
...
...
@eric-nord
Copy link

eric-nord commented May 13, 2016

Spelling - libraby-> library

@Synesso
Copy link

Synesso commented Jan 28, 2019

Thank you. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment