Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        internal ForkNode(ForkNode parent)
        {
            Debug.Assert(parent != null);
            Debug.Assert(parent != this);

            LookAheadQueue = parent.LookAheadQueue;
            MasterScanner = parent.MasterScanner;

            Children = new List<ForkNode>();
            Parent = parent;
        }
Ejemplo n.º 3
0
        internal ForkNode(ForkNode parent)
        {
            Debug.Assert(parent != null);
            Debug.Assert(parent != this);

            LookAheadQueue = parent.LookAheadQueue;
            MasterScanner  = parent.MasterScanner;

            Children = new List <ForkNode>();
            Parent   = parent;
        }
Ejemplo n.º 4
0
        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]);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        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();
                }
            }
        }
Ejemplo n.º 10
0
 public abstract void Remove(ForkNode child);
Ejemplo n.º 11
0
 public override void Remove(ForkNode child)
 {
     Debug.Assert(Node.Children.Count == 0);
     throw new NotSupportedException();
 }
Ejemplo n.º 12
0
 protected NodeState(ForkNode node)
 {
     
     Node = node;
 }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
 public BranchState(ForkNode node) : base(node) { }
Ejemplo n.º 16
0
        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);
            }
        }
Ejemplo n.º 17
0
 public HeadState(ForkNode node) : base(node) { }
Ejemplo n.º 18
0
 public BranchState(ForkNode node) : base(node)
 {
 }
Ejemplo n.º 19
0
        internal static ForkableScanner Create(Scanner masterScanner)
        {
            ForkNode node = new ForkNode();
            node.State = new TailHeadState(node);
            node.MasterScanner = masterScanner;

            return new ForkableScanner(node);
        }
Ejemplo n.º 20
0
        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);
            }
        }
Ejemplo n.º 21
0
 public TailHeadState(ForkNode node) : base(node)
 {
 }
Ejemplo n.º 22
0
 public TailState(ForkNode node) : base(node) { }
Ejemplo n.º 23
0
 private ForkableScanner(ForkNode node)
 {
     m_node = node;
 }
Ejemplo n.º 24
0
 protected NodeState(ForkNode node)
 {
     Node = node;
 }
Ejemplo n.º 25
0
 public override void Remove(ForkNode child)
 {
     Debug.Assert(Node.Children.Count == 0);
     throw new NotSupportedException();
 }
Ejemplo n.º 26
0
        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;
        }
Ejemplo n.º 27
0
 public abstract void Remove(ForkNode child);