Triple Search Tree Insensitive

I used the Ternary Search Tree for a while as the data structure implemented an automatic full drop-down combo box. This means that when the user enters "fo", a combo box will display

Foo nutrition soccer

The problem is that my current Triple Tree Search is case sensitive. My implementation is as follows. It was used by the real world for about 1 ++ yes. Therefore, I find it quite reliable.

My 3D Search Tree Code

However, I am looking for a case-insensitive Ternary Search Tree, which means that when I type "fo" the combo box will show me

Foo Nutrition FOOTBALL

Here are some key interfaces for TST where I hope the new random TST can have a similar interface.

    /** 
 * Stores value in the TernarySearchTree. The value may be retrieved using key.
 * @param key A string that indexes the object to be stored.
 * @param value The object to be stored in the tree.
 */    
public void put(String key, E value) {
    getOrCreateNode(key).data = value;
}

/**
 * Retrieve the object indexed by key.
 * @param key A String index.
 * @return Object The object retrieved from the TernarySearchTree.
 */
public E get(String key) {
    TSTNode<E> node = getNode(key);
    if(node==null) return null;
    return node.data;
}

The following is an example of use. TSTSearchEngine uses TernarySearchTree as its primary foundation.

Triple Search Tree Example

// There is stock named microsoft and MICROChip inside stocks ArrayList.
TSTSearchEngine<Stock> engine = TSTSearchEngine<Stock>(stocks);
// I wish it would return microsoft and MICROCHIP. Currently, it just return microsoft.
List<Stock> results = engine.searchAll("micro"); 
+3
source share
3 answers

One of the key factors that make my current Triple Search Tree difficult to maintain case-insensitive search is that my underlying data structure is a one-to-one mapping. Check out the following test code:

public void testPut() {
    System.out.println("put");
    Name name0 = new Name("abc");
    Name name1 = new Name("abc");
    TernarySearchTree<Name> instance = new TernarySearchTree<Name>();
    instance.put(name0.toString(), name0);
    instance.put(name1.toString(), name1);
    assertEquals(2, instance.matchPrefix("a").size()); // fail here. Result is 1
}

, TSTSearchEngine TernarySearchTree. TSTSearchEngine

(1) TernarySearchTree, UPPER-CASE .

(2) String-To-ArrayList.

, :

TSTSearchEngine<Name> engine = TSTSearchEngine<Name>();
engine.put(name0); // name0 is new Name("Abc");
engine.put(name1); // name0 is new Name("aBc");

(1) name0.toString() UPPER-CASE ( "ABC" ). TernarySearchTree. "ABC" TernarySearchTree.

(2) "ABC" , name0 .

(3) 1.toString() UPPER-CASE ( "ABC" ). TernarySearchTree. S1 TernarySearchTree.

(4) "ABC" , 1 .

engine.searchAll("a");

(1) TernarySearchTree "ABC" .

(2) "ABC" . , name0 name1.

. TSTSearchEngine

, . , ++ ++ . , , ++ Java.

+3

TST, , , , ? , .

+1

Source: https://habr.com/ru/post/1704322/