/** * Private internal method to recursively add the wordPart to the trie structure * * @param wordPart Word part to be added to the trie */ private int addInternal(TrieNode node, String wordPart, boolean isFullWord, int cost) { cost += 1; // LOGGER.debugprintln("\t\t" + this.getClass().getSimpleName() + // ": adding wordPart: " + wordPart + ", currentCost: " + cost); int length = wordPart.length(); node.children = (node.children != null) ? node.children : new TCharObjectHashMap<TrieNode>(1, 0.9f); char c = getChar(wordPart); TrieNode child = node.children.get(c); if (child == null) { child = new TrieNode(c); node.children.put(c, child); } if (length == 1) { // This is the end of the string and not on the root // node, add a child marker to denote end of suffix child.isEnd = true; child.isFullWordEnd = child.isFullWordEnd || isFullWord; } else { String subString = getSubstring(wordPart); cost += addInternal(child, subString, isFullWord, cost); if (createFullTrie && node.isRootNode()) { // full tree and root node cost += addInternal(node, subString, false, cost); } } return cost; }
/** * Creates new instance of {@link CharHashMapTrieNode}. */ public CharHashMapTrieNode() { next = new TCharObjectHashMap<CharHashMapTrieNode<T>>(); }
public <V> Map<Character, V> createMap() { return new TCharObjectMapDecorator<V>(new TCharObjectHashMap<V>(0)); }
/** * Creates new instance of {@link CharHashMapTrieNode} with specific initial capacity. * * @param initialCapacity the initial capacity */ public CharHashMapTrieNode(int initialCapacity) { next = new TCharObjectHashMap<CharHashMapTrieNode<T>>(initialCapacity); }
/** * Creates new instance of {@link CharHashMapTrieNode} with specific initial capacity and load factor. * * @param initialCapacity the initial capacity * @param loadFactor the load factor */ public CharHashMapTrieNode(int initialCapacity, float loadFactor) { next = new TCharObjectHashMap<CharHashMapTrieNode<T>>(initialCapacity, loadFactor); }