void Forward(ForkNode child) { // dequeue "offset" times // destroy Node // change child's state to TailHead or Tail Debug.Assert(Node.Offset == 0); for (int i = 0; i < child.Offset; i++) { Node.LookAheadQueue.Dequeue(); } child.Offset = 0; Node.Children.Clear(); Node.Destroy(); Debug.Assert(child.State is HeadState || child.State is BranchState, "Invalid child state when forwarding"); child.Parent = null; if (child.State is HeadState) { child.State = new TailHeadState(child); } else { child.State = new TailState(child); } }
internal ForkNode(ForkNode parent) { Debug.Assert(parent != null); Debug.Assert(parent != this); LookAheadQueue = parent.LookAheadQueue; MasterScanner = parent.MasterScanner; Children = new List<ForkNode>(); Parent = parent; }
internal ForkNode(ForkNode parent) { Debug.Assert(parent != null); Debug.Assert(parent != this); LookAheadQueue = parent.LookAheadQueue; MasterScanner = parent.MasterScanner; Children = new List <ForkNode>(); Parent = parent; }
public ForkableScanner Fork() { if (m_node.MasterScanner == null) { throw new ObjectDisposedException(null); } var forked = m_node.State.Fork(2); m_node = forked[0]; return new ForkableScanner(forked[1]); }
public override ForkNode[] Fork(int count) { Debug.Assert(Node.Children.Count >= 2); ForkNode[] results = new ForkNode[count]; for (int i = 0; i < count; i++) { results[i] = new ForkNode(Node); results[i].State = new HeadState(results[i]); Node.Children.Add(results[i]); } //no switching state return(results); }
public override void Remove(ForkNode child) { //remove child from Node bool succ = Node.Children.Remove(child); Debug.Assert(succ); Debug.Assert(Node.Children.Count > 0); //check if forwarding necessory if (Node.Children.Count == 1) { ForkNode onlyChild = Node.Children[0]; //forward to onlyChild Forward(onlyChild); } }
public override ForkNode[] Fork(int count) { Debug.Assert(count >= 2); Debug.Assert(Node.Children.Count == 0); ForkNode[] results = new ForkNode[count]; for (int i = 0; i < count; i++) { results[i] = new ForkNode(Node); results[i].State = new HeadState(results[i]); Node.Children.Add(results[i]); } //switch to TailState after fork Node.State = new TailState(this); return(results); }
private void Forward(ForkNode child) { //1. add node's children to its parent's children list //2. remove node from its parent's children list ForkNode parent = Node.Parent; parent.Children.Add(child); child.Offset += Node.Offset; Debug.Assert(parent != child); child.Parent = parent; Node.Offset = 0; Node.Children.Clear(); parent.Children.Remove(Node); //destroy Node Node.Destroy(); }
public void Join(ForkableScanner child) { CodeContract.RequiresArgumentNotNull(child, "child"); CodeContract.Requires(child.m_node.MasterScanner != null, "The scanner to join with has been closed"); CodeContract.Requires(child.m_node.Parent == m_node.Parent, "child", "The scanner to join does not share the parent node with current scanner"); var parent = m_node.Parent; //swap "this" with "child" var temp = m_node; m_node = child.m_node; child.m_node = temp; //close other children foreach (var otherChild in parent.Children.ToArray()) { if (otherChild != m_node) { otherChild.Close(); } } }
public abstract void Remove(ForkNode child);
public override void Remove(ForkNode child) { Debug.Assert(Node.Children.Count == 0); throw new NotSupportedException(); }
protected NodeState(ForkNode node) { Node = node; }
public override ForkNode[] Fork(int count) { Debug.Assert(count >= 2); Debug.Assert(Node.Children.Count == 0); ForkNode[] results = new ForkNode[count]; for (int i = 0; i < count; i++) { results[i] = new ForkNode(Node); results[i].State = new HeadState(results[i]); Node.Children.Add(results[i]); } //switch to TailState after fork Node.State = new TailState(this); return results; }
public BranchState(ForkNode node) : base(node) { }
public HeadState(ForkNode node) : base(node) { }
internal static ForkableScanner Create(Scanner masterScanner) { ForkNode node = new ForkNode(); node.State = new TailHeadState(node); node.MasterScanner = masterScanner; return new ForkableScanner(node); }
public TailHeadState(ForkNode node) : base(node) { }
public TailState(ForkNode node) : base(node) { }
private ForkableScanner(ForkNode node) { m_node = node; }
public override ForkNode[] Fork(int count) { Debug.Assert(Node.Children.Count >= 2); ForkNode[] results = new ForkNode[count]; for (int i = 0; i < count; i++) { results[i] = new ForkNode(Node); results[i].State = new HeadState(results[i]); Node.Children.Add(results[i]); } //no switching state return results; }