Beispiel #1
0
        public MapSumTrieNode GetPrefixNode(string prefix)
        {
            MapSumTrieNode current = root;

            for (int i = 0; i < prefix.Length; i++)
            {
                if (current.trieNodes[prefix[i] - 'a'] == null)
                {
                    return(null);
                }

                current = current.Next(prefix[i]);
            }
            return(current);
        }
Beispiel #2
0
        public void Insert(string key, int val)
        {
            MapSumTrieNode current = root;

            for (int i = 0; i < key.Length; i++)
            {
                if (current.trieNodes[key[i] - 'a'] == null)
                {
                    current.trieNodes[key[i] - 'a'] = new MapSumTrieNode();
                }

                current = current.Next(key[i]);
            }
            current.word = key;
            current.sum  = val;
        }