コード例 #1
0
        /// <summary>
        /// Create suffix trie
        /// </summary>
        public static StringTrie Create(string value, IEqualityComparer <char> comparer)
        {
            if (null == value)
            {
                throw new ArgumentNullException(nameof(value));
            }

            StringTrie result = new StringTrie(comparer);

            for (int start = 0; start < value.Length; ++start)
            {
                Node current = result.Root;

                current.Occurrences += 1;

                for (int i = start; i < value.Length; ++i)
                {
                    char c = value[i];

                    if (!current.Items.TryGetValue(c, out Node next))
                    {
                        next = new Node(result, current, c);
                    }

                    next.Occurrences += 1;
                    current           = next;
                }
            }

            // Empty Suffix
            result.Root.Occurrences += 1;

            return(result);
        }
コード例 #2
0
            // Standard Constructor
            internal Node(StringTrie trie, Node parent, char value)
            {
                Trie   = trie;
                Parent = parent;
                Value  = value;

                m_Items = new Dictionary <char, Node>(Trie.Comparer);

                if (Parent is not null)
                {
                    Parent.m_Items.Add(Value, this);
                }
            }