Example #1
0
        public override string ToString()
        {
            string str = "";

            for (HeapNode h = _heap; h != null; h = h.Next)
            {
                str += " " + h.ToString() + " ";
            }
            return(str);
        }
Example #2
0
        public Choicepoint(int arity, 
		                   EnvironmentFrame ce, 
		                   ProgramNode cp, 
		                   Choicepoint b,
		                   ProgramClause nextClause,
		                   int tr,
		                   HeapNode h)
        {
            _arity = arity;
                               _ce = ce;
                               _cp = cp;
                               _b = b;
                               _nextClause = nextClause;
                               _tr = tr;
                               _h = h;
        }
 public Choicepoint(int arity,
                    EnvironmentFrame ce,
                    ProgramNode cp,
                    Choicepoint b,
                    ProgramClause nextClause,
                    int tr,
                    HeapNode h)
 {
     _arity      = arity;
     _ce         = ce;
     _cp         = cp;
     _b          = b;
     _nextClause = nextClause;
     _tr         = tr;
     _h          = h;
 }
Example #4
0
        public void Custom()
        {
            HeapNode h = new HeapNode();
            EnvironmentFrame ce = new EnvironmentFrame();
            ProgramClause clause = new ProgramClause();
            Choicepoint b = new Choicepoint();
            ProgramNode cp = new ProgramNode();

            Choicepoint c = new Choicepoint(2, ce, cp, b, clause, 3, h);

            Assert.AreSame(h, c.H);
            Assert.AreEqual(2, c.Arity);
            Assert.AreSame(ce, c.CE);
            Assert.AreSame(cp, c.CP);
            Assert.AreSame(b, c.B);
            Assert.AreSame(clause, c.NextClause);
            Assert.AreEqual(3, c.TR);
        }
Example #5
0
        public void Push(HeapNode newItem)
        {
            if (newItem is AbstractTerm)
            {
                AbstractTerm at = newItem as AbstractTerm;
                if (at.IsReference)
                {
                    if (at.Name == null || at.Name == "")
                    {
                        at.Name = "__" + _variableIndex.ToString();
                        _variableIndex++;
                    }
                }
            }
            bool changeS = (_state.S == _extraItem);

            if (_h == null)
            {
                _heap               = newItem;
                _extraItem          = new HeapNode();
                newItem.Next        = _extraItem;
                _extraItem.Previous = newItem;
                _h = newItem;
                return;
            }


            _extraItem          = newItem;
            _extraItem.Previous = _h;
            _h.Next             = _extraItem;
            _h = _h.Next;
            if (changeS)
            {
                _state.S = _h;
            }

            HeapNode e = new HeapNode();

            _extraItem.Next = e;
            e.Previous      = _extraItem;
            _extraItem      = _extraItem.Next;
        }
Example #6
0
        public void Push(HeapNode newItem)
        {
            if (newItem is AbstractTerm)
            {
                AbstractTerm at = newItem as AbstractTerm;
                if (at.IsReference)
                {
                    if (at.Name == null || at.Name == "")
                    {
                        at.Name = "__" + _variableIndex.ToString();
                        _variableIndex++;
                    }
                }
            }
            bool changeS = (_state.S == _extraItem);
            if (_h == null)
            {
                _heap = newItem;
                _extraItem = new HeapNode();
                newItem.Next = _extraItem;
                _extraItem.Previous = newItem;
                _h = newItem;
                return;
            }

            _extraItem = newItem;
            _extraItem.Previous = _h;
            _h.Next = _extraItem;
            _h = _h.Next;
            if (changeS)
            {
                _state.S = _h;
            }

            HeapNode e = new HeapNode();
            _extraItem.Next = e;
            e.Previous = _extraItem;
            _extraItem = _extraItem.Next;
        }
Example #7
0
        //public void Push(HeapNode newItem)
        //{
        //    if (_h == null)
        //    {
        //        _heap = newItem;
        //        _h = newItem;
        //        return;
        //    }
        //    _h.Next = newItem;
        //    _previousItem = _h;
        //    _h = _h.Next;
        //    _h.Previous = _previousItem;
        //}

        public object Pop()
        {
            // if heap is empty, return null
            if (_h == null)
            {
                return(null);
            }
            // top of the heap
            HeapNode topOfHeap = _h;

            // if the heap doesn't have one item only, go backwards
            if (_h.Previous != null)
            {
                _h                  = _h.Previous;
                _h.Next             = _extraItem;
                _extraItem.Previous = _h;
            }
            else
            {
                _h = null;
            }

            return(topOfHeap);
        }
Example #8
0
        //public void Push(HeapNode newItem)
        //{
        //    if (_h == null)
        //    {
        //        _heap = newItem;
        //        _h = newItem;
        //        return;
        //    }
        //    _h.Next = newItem;
        //    _previousItem = _h;
        //    _h = _h.Next;
        //    _h.Previous = _previousItem;
        //}
        public object Pop()
        {
            // if heap is empty, return null
            if (_h == null)
            {
                return null;
            }
            // top of the heap
            HeapNode topOfHeap = _h;

            // if the heap doesn't have one item only, go backwards
            if (_h.Previous != null)
            {
                _h = _h.Previous;
                _h.Next = _extraItem;
                _extraItem.Previous = _h;
            }
            else
            {
                _h = null;
            }

            return topOfHeap;
        }
Example #9
0
        public void H()
        {
            Choicepoint c = new Choicepoint();

            HeapNode h = new HeapNode();

            c.H = h;

            Assert.AreSame(h, c.H);
        }