public EndPoint(SearchFsa <TItem> fsa, FoundDelegate foundDelegate = null) { if (fsa == null || !fsa.IsPrepared) { throw new ArgumentException(); } Fsa = fsa; TotalFound = foundDelegate; ResetState(); }
public EndPoint GetEndPoint(FoundDelegate action = null) { lock (Locker) { if (!IsPrepared) { throw new ArgumentException(); } var endPoint = new EndPoint(this, action); EndPoints.Add(endPoint); return(endPoint); } }
public void Dispose() { if (IsDisposed) { return; } if (Fsa != null) { Fsa.UnregisterEndPoint(this); } TotalFound = null; Fsa = null; IsDisposed = true; }
public bool TryFindUserData <TUserData>([NotNullWhen(returnValue: true)] out TUserData userData, Func <T, T, int> compare3, FoundDelegate <T, TUserData> found) where TUserData : struct { userData = default; // H5B.c (H5B_find) /* * Perform a binary search to locate the child which contains * the thing for which we're searching. */ (var index, var cmp) = this.LocateRecord(compare3); /* Check if not found */ if (cmp != 0) { return(false); } /* * Follow the link to the subtree or to the data node. */ var childAddress = this.ChildAddresses[(int)index]; var key = this.Keys[index]; if (this.NodeLevel > 0) { _reader.Seek((long)childAddress, SeekOrigin.Begin); var subtree = new BTree1Node <T>(_reader, _superblock, _decodeKey); if (subtree.TryFindUserData(out userData, compare3, found)) { return(true); } } else { if (found(childAddress, key, out userData)) { return(true); } } return(false); }
private void ProcessFinalNode(Node currentNode, FoundDelegate foundAction) { if (!currentNode.Final) { return; } var foundPosition = Position - currentNode.DataLength; if (foundAction != null) { foundAction(foundPosition, currentNode.FinalContext); } if (TotalFound != null) { TotalFound(foundPosition, currentNode.FinalContext); } }
/// <summary> /// /// </summary> /// <param name="searchArea"></param> /// <param name="found"></param> /// <param name="node"></param> private void FindContain(Box searchArea, Node node, FoundDelegate found) { for (int i = 0; i < node.Count; i++) { if (searchArea.Contains(node.Items[i].Bounds)) { if (node.IsLeaf) { found(GetItem(node.Items[i].ID)); } else { Node childNode = GetNode(node.Items[i].ID); FindContain(searchArea, childNode, found); } } } }
public void ProcessIncome(TItem income, FoundDelegate foundAction = null) { if (!Fsa.IsPrepared) { throw new ArgumentException("not prepared fsa!"); } Position++; var currentNode = Fsa.Nodes[State]; while (true) { if (currentNode.Jumps.ContainsKey(income)) { currentNode = currentNode.Jumps[income]; State = currentNode.Id; ProcessFinalNode(currentNode, foundAction); if (currentNode.HasFinalSuffix) { var suffixLink = currentNode.SuffixLink; while (suffixLink != suffixLink.SuffixLink) { ProcessFinalNode(suffixLink, foundAction); suffixLink = suffixLink.SuffixLink; } } break; } var suffLink = currentNode.SuffixLink; if (suffLink == currentNode) { break; } currentNode = suffLink; State = currentNode.Id; } }