codebytes: R-Way Tries Implementation - Java
Thursday, December 10, 2015 R-Way Tries Implementation - Java R-Way tries are useful for operations on strings. Tries trade-off space for computational time. Search hit : L Insert : L Source: class Node{ public char c; public Object v = null; public int n; public Node[] next; Node(char c, int R){ this.c = c; next = new Node[R]; } Node(int R) {next = new Node[R];} public String toString(){return ""+c;} } public class Trie
{ private final int R; private Node root; public void add(String s, T t){ root.next[s.charAt(0)] = addHelper(root.next[s.charAt(0)], s, 0, t); } private Node addHelper(Node node, String s, int i, T value){ if(node==null){ Node n = new Node(s.charAt(i), R); node = n; } if(i+1==s.length()){node.v = value; return node; } if(node.next[s.charAt(i+1)]==null)node.n++; node.next[s.charAt(i+1)] = addHelper(node.next[s.charAt(i+1)], s, i+1, value); return node; } public boolean delete(String s){ boolean r = deleteHelper(root.next[s.charAt(0)], s, 0); if(r && (--root.next[s.
Read full article from codebytes: R-Way Tries Implementation - Java
No comments:
Post a Comment