001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.collections4.trie; 018 019import java.util.Map; 020 021import org.apache.commons.collections4.trie.analyzer.StringKeyAnalyzer; 022 023/** 024 * Implementation of a PATRICIA Trie (Practical Algorithm to Retrieve Information 025 * Coded in Alphanumeric). 026 * <p> 027 * A PATRICIA {@link Trie} is a compressed {@link Trie}. Instead of storing 028 * all data at the edges of the {@link Trie} (and having empty internal nodes), 029 * PATRICIA stores data in every node. This allows for very efficient traversal, 030 * insert, delete, predecessor, successor, prefix, range, and {@link #select(Object)} 031 * operations. All operations are performed at worst in O(K) time, where K 032 * is the number of bits in the largest item in the tree. In practice, 033 * operations actually take O(A(K)) time, where A(K) is the average number of 034 * bits of all items in the tree. 035 * <p> 036 * Most importantly, PATRICIA requires very few comparisons to keys while 037 * doing any operation. While performing a lookup, each comparison (at most 038 * K of them, described above) will perform a single bit comparison against 039 * the given key, instead of comparing the entire key to another key. 040 * <p> 041 * The {@link Trie} can return operations in lexicographical order using the 042 * 'prefixMap', 'submap', or 'iterator' methods. The {@link Trie} can also 043 * scan for items that are 'bitwise' (using an XOR metric) by the 'select' method. 044 * Bitwise closeness is determined by the {@link KeyAnalyzer} returning true or 045 * false for a bit being set or not in a given key. 046 * <p> 047 * This PATRICIA {@link Trie} supports both variable length & fixed length 048 * keys. Some methods, such as {@link #prefixMap(Object)} are suited only 049 * to variable length keys. 050 * 051 * @see <a href="http://en.wikipedia.org/wiki/Radix_tree">Radix Tree</a> 052 * @see <a href="http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/PATRICIA">PATRICIA</a> 053 * @see <a href="http://www.imperialviolet.org/binary/critbit.pdf">Crit-Bit Tree</a> 054 * @since 4.0 055 * @version $Id: PatriciaTrie.html 972421 2015-11-14 20:00:04Z tn $ 056 */ 057public class PatriciaTrie<E> extends AbstractPatriciaTrie<String, E> { 058 059 private static final long serialVersionUID = 4446367780901817838L; 060 061 public PatriciaTrie() { 062 super(new StringKeyAnalyzer()); 063 } 064 065 public PatriciaTrie(final Map<? extends String, ? extends E> m) { 066 super(new StringKeyAnalyzer(), m); 067 } 068 069}