private AhoCorasickTreeNode(AhoCorasickTreeNode parent, char key) { Key = key; Parent = parent; _size = (char)0; _entries = new Entry[0]; }
private AhoCorasickTreeNode(AhoCorasickTreeNode parent, char key) { Key = key; Parent = parent; _buckets = new int[0]; _entries = new Entry[0]; Results = new List <string>(); }
public void AddTransition_Twice_AddedTransitionsCanBeRetrievedAsEnumerable() { // arrange var node = new AhoCorasickTreeNode(); // act node.AddTransition('a'); node.AddTransition('b'); // assert Assert.AreEqual(2, node.Transitions.Count()); }
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); }
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(); }
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); }
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(); }
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); } }
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; }
private AhoCorasickTreeNode(AhoCorasickTreeNode parent, char key) { Key = key; Parent = parent; _buckets = new int[0]; _entries = new Entry[0]; Results = new List<string>(); }