Пример #1
0
 private AhoCorasickTreeNode(AhoCorasickTreeNode parent, char key)
 {
     Key      = key;
     Parent   = parent;
     _size    = (char)0;
     _entries = new Entry[0];
 }
Пример #2
0
            private AhoCorasickTreeNode(AhoCorasickTreeNode parent, char key)
            {
                Key    = key;
                Parent = parent;

                _buckets = new int[0];
                _entries = new Entry[0];
                Results  = new List <string>();
            }
Пример #3
0
        public void AddTransition_Twice_AddedTransitionsCanBeRetrievedAsEnumerable()
        {
            // arrange
            var node = new AhoCorasickTreeNode();

            // act
            node.AddTransition('a');
            node.AddTransition('b');

            // assert
            Assert.AreEqual(2, node.Transitions.Count());
        }
Пример #4
0
        public void AddResult_Twice_OnlyGetsAddedOnce()
        {
            // arrange
            var node = new AhoCorasickTreeNode();

            // act
            node.AddResults(new[] { "test", "test" });

            // assert
            Assert.AreEqual(1, node.Results.Count());
            CollectionAssert.AllItemsAreUnique(node.Results);
        }
Пример #5
0
        public AhoCorasickTree(string[] keywords)
        {
            if (keywords == null) throw new ArgumentNullException("keywords");
            if (keywords.Length == 0) throw new ArgumentException("should contain keywords");

            _rootNode = new AhoCorasickTreeNode();

            var length = keywords.Length;
            for (var i = 0; i < length; i++)
            {
                AddPatternToTree(keywords[i]);
            }

            SetFailures();
        }
Пример #6
0
            public AhoCorasickTreeNode AddNode(char key)
            {
                var node = new AhoCorasickTreeNode(this, key);

                var newSize = _count + 1;

                Resize(newSize);

                var targetBucket = key % newSize;

                _entries[_count].Key   = key;
                _entries[_count].Value = node;
                _entries[_count].Next  = _buckets[targetBucket];
                _buckets[targetBucket] = _count;
                _count++;

                return(node);
            }
Пример #7
0
        public AhoCorasickTree(string[] keywords)
        {
            if (keywords == null)
            {
                throw new ArgumentNullException("keywords");
            }
            if (keywords.Length == 0)
            {
                throw new ArgumentException("should contain keywords");
            }

            _rootNode = new AhoCorasickTreeNode();

            var length = keywords.Length;

            for (var i = 0; i < length; i++)
            {
                AddPatternToTree(keywords[i]);
            }

            SetFailures();
        }
Пример #8
0
            public AhoCorasickTreeNode AddNode(char key)
            {
                var node = new AhoCorasickTreeNode(this, key);

                if (_size == 0)
                {
                    Resize();
                }

                while (true)
                {
                    var ind = (char)(key & (_size - 1));

                    if (_entries[ind].Key != 0 && _entries[ind].Key != key)
                    {
                        Resize();
                        continue;
                    }

                    _entries[ind].Key   = key;
                    _entries[ind].Value = node;
                    return(node);
                }
            }
Пример #9
0
            public AhoCorasickTreeNode AddNode(char key)
            {
                var node = new AhoCorasickTreeNode(this, key);

                var newSize = _count + 1;
                Resize(newSize);

                var targetBucket = key % newSize;
                _entries[_count].Key = key;
                _entries[_count].Value = node;
                _entries[_count].Next = _buckets[targetBucket];
                _buckets[targetBucket] = _count;
                _count++;

                return node;
            }
Пример #10
0
            private AhoCorasickTreeNode(AhoCorasickTreeNode parent, char key)
            {
                Key = key;
                Parent = parent;

                _buckets = new int[0];
                _entries = new Entry[0];
                Results = new List<string>();
            }