🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

autocomplete-trie-search

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autocomplete-trie-search

Autocomplete trie search is a powerful technique used in information retrieval systems to provide fast and accurate suggestions to users as they type in their queries. This technique uses a trie data structure to store a set of strings, enabling quick and efficient prefix-based search. As the user types in their query, the autocomplete trie search algorithm traverses the trie to find all possible completions of the prefix, returning a list of suggestions ranked by relevance. This technique is commonly used in search engines, text editors, and other applications that require fast and accurate query completion. With its ability to provide real-time suggestions, autocomplete trie search enhances the user experience, making it easier for users to find the information they need quickly and efficiently.

1.0.6
Source
NuGet
Version published
Maintainers
1
Created
Source

A trie data structure implementation for autocomplete search.

Implementation

using autocomplete_trie_search;
using autocomplete_trie_search.Interface;
using System.Diagnostics;

namespace autocomplete_trie_search_unit_test
{
    public class Tests
    {
        private AutoCompleteTrieSearch search;
    
        [SetUp]
        public void Setup()
        {
            search = new AutoCompleteTrieSearch();
        }

        [Test]
        public void InsertBySingleElement()
        {
            INodeValue node = new NodeValueOptions()
            {
                Text = "Some text",
                Value = new {Id = 1, Text = "I am okay"},
                Weight = 10
            };

            Assert.IsTrue(search.InsertOrUpdate(node));
        }

        [Test]
        public void InsertByMultipleElement()
        {
            List<INodeValue> nodes = new List<INodeValue>();
       
            for(int i = 0; i<=100000; i++)
            {
                INodeValue node = new NodeValueOptions()
                {
                    Text = Guid.NewGuid().ToString(),
                    Value = new { Id = 1, Text = "I am okay" },
                    Weight = 10
                };
            
                nodes.Add(node);
            }

            Assert.IsTrue(search.InsertOrUpdate(nodes));
        }


        [Test]
        public void Insert100000ElementTimeComplexity()
        {
            List<INodeValue> nodes = new List<INodeValue>();

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            for (int i = 0; i <= 100000; i++)
            {
                INodeValue node = new NodeValueOptions()
                {
                    Text = Guid.NewGuid().ToString(),
                    Value = new { Id = 1, Text = "I am okay" },
                    Weight = 10
                };

                nodes.Add(node);
            }
        
            search.InsertOrUpdate(nodes);
            stopwatch.Stop();

        
            Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, 12000);
        }

        [Test]
        public void Insert10000ElementTimeComplexity()
        {
            List<INodeValue> nodes = new List<INodeValue>();

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            for (int i = 0; i <= 10000; i++)
            {
                INodeValue node = new NodeValueOptions()
                {
                    Text = Guid.NewGuid().ToString(),
                    Value = new { Id = 1, Text = "I am okay" },
                    Weight = 10
                };

                nodes.Add(node);
            }

            search.InsertOrUpdate(nodes);
            stopwatch.Stop();


            Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, 2000);
        }


        [Test]
        public void NodeCountFor10000Element()
        {
            List<INodeValue> nodes = new List<INodeValue>();

            for (int i = 0; i <= 100000; i++)
            {
                INodeValue node = new NodeValueOptions()
                {
                    Text = Guid.NewGuid().ToString().Substring(0,16),
                    Value = new { Id = 1, Text = "I am okay" },
                    Weight = 10
                };

                nodes.Add(node);
            }

            search.InsertOrUpdate(nodes);
            Assert.LessOrEqual(search.GetNodeCount(), 800000);
        }

        [Test]
        public void MemoryUsageFor10000Element()
        {
            Process process = Process.GetCurrentProcess();
            long startMemory = process.WorkingSet64;

            List<INodeValue> nodes = new List<INodeValue>();

            for (int i = 0; i <= 20000; i++)
            {
                INodeValue node = new NodeValueOptions()
                {
                    Text = Guid.NewGuid().ToString().Substring(0, 16),
                    Value = new { Id = 1, Text = "I am okay" },
                    Weight = 10
                };

                nodes.Add(node);
            }

            search.InsertOrUpdate(nodes);

            process = Process.GetCurrentProcess();
            long endMemory = process.WorkingSet64;
            long memoryUsed = endMemory - startMemory;

            Console.WriteLine("Memory used: {0:N0} bytes", memoryUsed);

            Assert.LessOrEqual(memoryUsed, 165 * 1024 * 1024);
        }
    }
}

Keywords

autocomplete

FAQs

Package last updated on 28 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts