Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
trie_multiple_search.cpp File Reference

Trie datastructure with search variants More...

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstring>
#include <iostream>
#include <queue>
Include dependency graph for trie_multiple_search.cpp:

Classes

class  operations_on_datastructures::trie_operations::Tnode
 Class defining the structure of trie node and containing the methods to perform operations on them. More...
 

Namespaces

namespace  operations_on_datastructures
 for std::vector
 
namespace  trie_operations
 Functions for Trie datastructure implementation.
 

Functions

static void test ()
 Function to test a simple search before and after deleting an entry. And to test out the multiple variants of search.
 
int main (int argc, char const *argv[])
 Main function.
 

Detailed Description

Trie datastructure with search variants

This provides multiple variants of search functions on a trie structure utilizing STL. The trie is valid for only English alphabets.

Author
Ghanashyam

Function Documentation

◆ main()

int main ( int argc,
char const * argv[] )

Main function.

Parameters
argccommandline argument count (ignored)
argvcommandline array of arguments (ignored)
Returns
0 on exit
463 {
464 test(); // run self-test implementations
465 return 0;
466}
static void test()
Function to test a simple search before and after deleting an entry. And to test out the multiple var...
Definition trie_multiple_search.cpp:422
Here is the call graph for this function:

◆ test()

static void test ( )
static

Function to test a simple search before and after deleting an entry. And to test out the multiple variants of search.

422 {
424 std::vector<std::string> inputs = {
425 "abcde", "sss", "ssss", "ssst", "sssu", "sssv",
426 "sst", "ssts", "sstt", "sstu", "tutu", "tutuv",
427 "tutuu", "tutuvs", "tutus", "tvst", "tvsu", "vvvv"};
428
429 for (auto &i : inputs) {
430 root->Insert(i);
431 }
432 // Search an existing entry
433 assert(root->SearchPresence("vvvv"));
434 std::cout << root->SearchPresence("vvvv") << std::endl;
435 // Delete it
436 root->Delete("vvvv");
437 // Search for the entry again
438 assert(!root->SearchPresence("vvvv"));
439 std::cout << root->SearchPresence("vvvv") << std::endl;
440
441 std::cout << root->SearchPresence("tutu") << std::endl;
442 root->SearchSuggestions("tutu");
443 std::cout << root->SearchPresence("tutu") << std::endl;
444
445 root->SearchSuggestions("tutuv");
446 std::cout << root->SearchPresence("tutuv") << std::endl;
447
448 root->SearchSuggestions("tutuvs");
449
450 root->SearchFreqSuggestions(
451 "tu"); // The top 3 frequent entries with prefix tu are tutu, tutuv &
452 // tutuvs respectively
453 root->SearchSuggestions(
454 ""); // Empty search to list all the entries in the trie
455}
Class defining the structure of trie node and containing the methods to perform operations on them.
Definition trie_multiple_search.cpp:34
T endl(T... args)
Here is the call graph for this function: