Package: nf-prefix-tree
No Frills Prefix Tree (nf_prefix_tree)This is a prefix tree with no frills. Supports simple insert, search, and basic querying of strings that a (can be) keyed. Written in C++ 11 and has python wrappers. Written because I couldn't find a fast, easy to install and use basic prefix tree in python.InstallationC++In order to build the C++, you need to haveC++ 11g++compilerThis program uses theSTLso no other packages are necessaryLinux and macOSChange to thenf_prefix_treedirectoryRunchmod +x buildAndTest.shRun./buildAndTest.shIf no errors occur, you should be good to go!WindowsIn order to build, ensure you have theg++compiler and it is added to pathChange tonf_prefix_tree/src/directoryRunmakeChange tonf_prefix_tree/tests/directory if you want to run testsRunmakeRun./testmainPythonIf you are installing onpipand use macOS, all you need to run ispip install nf_prefix_treeOtherwise you will need to build from source. First follow the above steps for C++. After doing so, make sure you have the followingPython 3CythonpackageOnce you have these, change into thepython_bindingsdirectory. Runpython3 setup.py build_ext --inplace. You can now dofrom nf_prefix_tree import PyPrefixTreein the same directory!ExamplesC++#include"PrefixTree.hpp"intmain(){PrefixTree*t=newPrefixTree();t->addSequence("ABCDEFG","Key1");t->addSequence("ABCDEFG","Key2");t->addSequence("ABCXYZ","Key3");t->addSequence("LMNOP","Key4");t->show();t->show(2);}Output:root|->Sequence:Akeys:Key1,Key2,Key3,|->Sequence:ABkeys:Key1,Key2,Key3,|->Sequence:ABCkeys:Key1,Key2,Key3,|->Sequence:ABCDkeys:Key1,Key2,|->Sequence:ABCDEkeys:Key1,Key2,|->Sequence:ABCDEFkeys:Key1,Key2,|->Sequence:ABCDEFGkeys:Key1,Key2,|->Sequence:ABCXkeys:Key3,|->Sequence:ABCXYkeys:Key3,|->Sequence:ABCXYZkeys:Key3,|->Sequence:Lkeys:Key4,|->Sequence:LMkeys:Key4,|->Sequence:LMNkeys:Key4,|->Sequence:LMNOkeys:Key4,|->Sequence:LMNOPkeys:Key4,root|->Sequence:Akeys:Key1,Key2,Key3,|->Sequence:ABkeys:Key1,Key2,Key3,|->Sequence:Lkeys:Key4,|->Sequence:LMkeys:Key4,Pythonfromnf_prefix_treeimportPyPrefixTreet=PyPrefixTree()t.addSequence('ABCDE','key1')t.addSequence('ABCXY','key2')t.addSequence('ZYAPW','key3')t.show()Output:root|->Sequence:Akeys:key1,key2,|->Sequence:ABkeys:key1,key2,|->Sequence:ABCkeys:key1,key2,|->Sequence:ABCDkeys:key1,|->Sequence:ABCDEkeys:key1,|->Sequence:ABCXkeys:key2,|->Sequence:ABCXYkeys:key2,|->Sequence:Zkeys:key3,|->Sequence:ZYkeys:key3,|->Sequence:ZYAkeys:key3,|->Sequence:ZYAPkeys:key3,|->Sequence:ZYAPWkeys:key3,APIC++PrefixTree()Constructor for the prefix treevoid addSequence(sequence, key)Add a sequence with a key to the prefix treesequence - std::stringthe sequence to compress via treekey - std::stringthe key for this sequence. If not desired, make sequence empty stringbool hasPrefix(prefix)Check to see if the input sequence is in the treeprefix - std::stringthe prefix to look upstd::vector<std::string> getKeysWithPrefix(prefix)Get all keys associated with a prefix. Empty vector returned if the prefix is not in the treeprefix - std::stringthe prefix to look forvoid show(level=-1)Show the tree in the console down to the specified levellevel -- intthe level down to which to print the tree. Leave as-1if you want to print the entire treePythonPyPrefixTree()Constructor for the prefix treeaddSequence(sequence, key) -> NoneAdd a sequence with a key to the prefix treesequence - strthe sequence to compress via treekey - strthe key for this sequence. If not desired, makehasPrefix(prefix) -> boolCheck to see if the input sequence is in the treeprefix - strthe prefix to look upReturnsTrueifprefixis found,FalseotherwisegetKeysWithPrefix(prefix) -> listGet all keys associated with a prefixprefix - strthe prefix to look forReturns alistofstrof all keys.[]is returned if the prefix is not in the treeshow(level=-1)Show the tree in the console down to the specified levellevel -- intthe level down to which to print the tree. Leave as-1if you want to print the entire tree