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 *      https://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;
022import org.apache.commons.collections4.trie.analyzer.StringKeyAnalyzer;
023
024/**
025 * Implements a PATRICIA Trie (Practical Algorithm to Retrieve Information
026 * Coded in Alphanumeric).
027 * <p>
028 * A PATRICIA {@link Trie} is a compressed
029 * {@link Trie}. Instead of storing
030 * all data at the edges of the {@link Trie}
031 * (and having empty internal nodes), PATRICIA stores data in every node.
032 * This allows for very efficient traversal, insert, delete, predecessor,
033 * successor, prefix, range, and {@link #select(Object)}
034 * operations. All operations are performed at worst in O(K) time, where K
035 * is the number of bits in the largest item in the tree. In practice,
036 * operations actually take O(A(K)) time, where A(K) is the average number of
037 * bits of all items in the tree.
038 * </p>
039 * <p>
040 * Most importantly, PATRICIA requires very few comparisons to keys while
041 * doing any operation. While performing a lookup, each comparison (at most
042 * K of them, described above) will perform a single bit comparison against
043 * the given key, instead of comparing the entire key to another key.
044 * </p>
045 * <p>
046 * The {@link Trie} can return operations in
047 * lexicographical order using the 'prefixMap', 'submap', or 'iterator' methods.
048 * The {@link Trie} can also
049 * scan for items that are 'bitwise' (using an XOR metric) by the 'select' method.
050 * Bitwise closeness is determined by the {@link KeyAnalyzer} returning true or
051 * false for a bit being set or not in a given key.
052 * </p>
053 * <p>
054 * This PATRICIA {@link Trie} supports both variable
055 * length &amp; fixed length keys. Some methods, such as {@link org.apache.commons.collections4.Trie#prefixMap(Object)}
056 * are suited only to variable length keys.
057 * </p>
058 *
059 * @param <V> The type of the values in this map
060 * @see <a href="https://en.wikipedia.org/wiki/Radix_tree">Radix Tree</a>
061 * @see <a href="https://users.monash.edu/~lloyd/tildeAlgDS/Tree/PATRICIA/">PATRICIA</a>
062 * @see <a href="https://www.imperialviolet.org/binary/critbit.pdf">Crit-Bit Tree</a>
063 * @since 4.0
064 */
065public class PatriciaTrie<V> extends AbstractPatriciaTrie<String, V> {
066
067    private static final long serialVersionUID = 4446367780901817838L;
068
069    /**
070     * Constructs a new instance.
071     */
072    public PatriciaTrie() {
073        super(StringKeyAnalyzer.INSTANCE);
074    }
075
076    /**
077     * Constructs a new instance.
078     *
079     * @param map mappings to be stored in this map.
080     */
081    public PatriciaTrie(final Map<? extends String, ? extends V> map) {
082        super(StringKeyAnalyzer.INSTANCE, map);
083    }
084
085}