Exemplo n.º 1
0
        internal TrieNode <T> SearchNode(string key)
        {
            TrieKeyReader keyReader = new TrieKeyReader(key);
            TrieNode <T>  node      = root;

            while (node != null && !keyReader.IsFinished)
            {
                node = node[keyReader.ReadChunk()];
            }
            return(node != null && node.IsTerminal ? node : null);
        }
Exemplo n.º 2
0
        public void Insert(string key, T tag)
        {
            Guard.IsNotNull(key, nameof(key));
            TrieKeyReader keyReader = new TrieKeyReader(key);

            TrieNode <T> node = root;

            while (!keyReader.IsFinished)
            {
                int index = keyReader.ReadChunk();
                var child = node[index];
                if (child == null || (keyReader.IsFinished && !child.IsTerminal))
                {
                    node[index] = child = keyReader.IsFinished ? new TrieNode <T>(tag, true) : new TrieNode <T>();
                }
                node = child;
            }
        }
Exemplo n.º 3
0
        public void Delete(string key)
        {
            Guard.IsNotNull(key, nameof(key));
            TrieKeyReader keyReader = new TrieKeyReader(key);

            TrieNode <T> node  = root;
            TrieNode <T> prev  = null;
            int          index = -1;

            while (node != null && !keyReader.IsFinished)
            {
                prev  = node;
                index = keyReader.ReadChunk();
                node  = node[index];
            }
            if (node != null && node.IsTerminal)
            {
                prev[index] = new TrieNode <T>();
            }
        }