Exemple #1
0
        public void InsertTest(IHeap <int> heap, bool isMin)
        {
            var newList = RandomList().ToList();
            var tmpLst  = new List <int>(TestList);

            tmpLst.AddRange(newList);
            tmpLst.Sort();
            if (!isMin)
            {
                tmpLst.Reverse();
            }
            foreach (var num in newList)
            {
                heap.Insert(num);
            }
            var heapList = new List <int>();

            while (!heap.IsEmpty())
            {
                heapList.Add(heap.ExtractMin().Value);
            }
            Console.WriteLine("isMin:" + isMin);
            Console.WriteLine("Expect:" + string.Join(", ", tmpLst));
            Console.WriteLine("Result:" + string.Join(", ", heapList));
            Assert.IsTrue(tmpLst.SequenceEqual(heapList));
        }
 private static IEnumerable <TSource> ConsumeHeap <TSource>(this IHeap <TSource> heap)
 {
     while (heap.Count > 0)
     {
         yield return(heap.Remove());
     }
 }
Exemple #3
0
        /// <summary>
        /// Returns a typed space for objects of the specified type
        /// </summary>
        public static ISpace <T> GetSpace <T>(this IHeap heap) where T : HeapObject
        {
            var atr  = HeapAttribute.Lookup <HeapSpaceAttribute>(typeof(T));
            var area = heap.NonNull(nameof(heap))[atr.Area];

            return(area.GetSpace <T>());
        }
Exemple #4
0
 protected BTree(
     IHdfStreamProvider aStreamProvider,
     IHeap aAllocator)
 {
     mrStreamProvider       = aStreamProvider;
     mrStreamSpaceAllocator = aAllocator;
 }
        public void MergeTest(IHeap <int> heap, bool isMin)
        {
            var newList = RandomList().ToList();
            var tmpLst  = new List <int>(TestList);

            tmpLst.AddRange(newList);
            tmpLst.Sort();
            if (!isMin)
            {
                tmpLst.Reverse();
            }
            var newHeap = CreateHeap(isMin) as BinomialHeap <int>;

            Assert.NotNull(newHeap);
            foreach (var num in newList)
            {
                newHeap.Insert(num);
            }
            var binaryHeap = heap as BinomialHeap <int>;

            Assert.IsNotNull(binaryHeap);
            binaryHeap.Merge(newHeap);
            var heapList = GetHeapList(isMin).ToList();

            Console.WriteLine("isMin:" + isMin);
            Console.WriteLine("Expect:" + string.Join(", ", tmpLst));
            Console.WriteLine("Result:" + string.Join(", ", heapList));
            Assert.IsTrue(tmpLst.SequenceEqual(heapList));
        }
Exemple #6
0
        public static async Task <SaveResult <object> > ExecResultAsync(this IHeap heap, HeapRequest query, Guid idempotencyToken = default(Guid), INode node = null)
        {
            var atr  = HeapAttribute.Lookup <HeapProcAttribute>(query.NonNull(nameof(query)).GetType());
            var area = heap.NonNull(nameof(heap))[atr.Area];

            return(await area.ExecuteAsync(query, idempotencyToken, node));
        }
Exemple #7
0
        public void EmptyFlagFalseInNonEmptyHeap()
        {
            IHeap <int> heap = NewHeapInstance <int>();

            heap.Insert(5);
            Assert.IsFalse(heap.IsEmpty);
        }
Exemple #8
0
        public void SizeIsOneInOneEntryHeap()
        {
            IHeap <int> heap = NewHeapInstance <int>();

            heap.Insert(5);
            Assert.AreEqual(1, heap.Size);
        }
        public void Pop_N_TryPop_Behaves_For_Empty_Heap(int capacity)
        {
            IHeap <int> instance = Substitute.ForPartsOf <AbstractBinaryHeap <int> >(capacity);

            Assert.Throws <IndexOutOfRangeException>(() => instance.Pop());
            Assert.False(instance.TryPop(out _));
        }
Exemple #10
0
 /// <summary>
 ///     Create a <see cref="PriorityQueue{T}" /> with given <see cref="IHeap{T}" />.
 ///     If no <see cref="IHeap{T}" /> is given, <see cref="BinaryHeap{T}" /> and <see cref="PriorityComparer{T}" /> will be
 ///     used.
 /// </summary>
 /// <param name="heap">Initial Heap.</param>
 public PriorityQueue(IHeap <IPriority <T> > heap = null)
 {
     if (heap == null)
     {
         heap = Heaps.Default(new PriorityComparer <T>());
     }
     _heap = heap;
 }
Exemple #11
0
 public HeapIntConnector(int dataAddress, HeapType dataType, IHeap heap, IHeapConnectorFactory heapDataFactory, DeallocationFunc deallocFunc)
     : base(dataAddress, dataType, heap, heapDataFactory, deallocFunc)
 {
     if (dataType.BuiltInType != BuiltInTypeEnum.Integer)
     {
         throw new InvalidOperationException("Invalid heap type!");
     }
 }
Exemple #12
0
        public void ExceptionThrownIfNullIsInserted()
        {
            IHeap <int?> heap = NewHeapInstance <int?>(
                10,
                (x, y) => Nullable.Compare(x, y));

            Assert.Throws <ArgumentNullException>(() => heap.Insert(null));
        }
 /// <summary>
 /// Constructs a HeapConnector instance.
 /// </summary>
 public HeapConnector(int dataAddress, HeapType dataType, IHeap heap, IHeapConnectorFactory heapDataFactory, DeallocationFunc deallocFunc)
 {
     this.dataAddress      = dataAddress;
     this.dataType         = dataType;
     this.heap             = heap;
     this.heapDataFactory  = heapDataFactory;
     this.deallocationFunc = deallocFunc;
 }
        private static Handle AllocateAndWrite(IHeap <byte> heap, string text)
        {
            var bytes  = Encoding.UTF8.GetBytes(text);
            var handle = heap.Allocate(bytes.Length);

            heap.Write(handle, bytes);
            return(handle);
        }
Exemple #15
0
 public ProgState(IStack es, IOutBuffer ob, IDictionary vt, int i, IHeap hp)
 {
     this.es = es;
     this.ob = ob;
     this.vt = vt;
     this.hp = hp;
     psId    = i;
 }
Exemple #16
0
        public void EmptyFlagTrueAfterHeapBecomesEmpty()
        {
            IHeap <int> heap = NewHeapInstance <int>();

            heap.Insert(5);
            heap.Remove();
            Assert.IsTrue(heap.IsEmpty);
        }
Exemple #17
0
 public PrgState(IStack<IStmt> stack, IDictionary<String, int> symbol_table, IList<int> output, IHeap<int> hp)
 {
     state_id = id_gen++;
     exeStack = stack;
     symTable = symbol_table;
     outList = output;
     h = hp;
 }
Exemple #18
0
 public PrgState(IStack <IStmt> stack, IDictionary <String, int> symbol_table, IList <int> output, IHeap <int> hp)
 {
     state_id = id_gen++;
     exeStack = stack;
     symTable = symbol_table;
     outList  = output;
     h        = hp;
 }
Exemple #19
0
        public void EmptyFlagTrueAfterHeapIsCleared()
        {
            IHeap <int> heap = NewHeapInstance <int>();

            heap.Insert(5);
            heap.Clear();
            Assert.IsTrue(heap.IsEmpty);
        }
Exemple #20
0
        public void SizeIsZeroAfterHeapBecomesEmpty()
        {
            IHeap <int> heap = NewHeapInstance <int>();

            heap.Insert(5);
            heap.Remove();
            Assert.AreEqual(0, heap.Size);
        }
Exemple #21
0
        public void SizeIsZeroAfterHeapIsCleared()
        {
            IHeap <int> heap = NewHeapInstance <int>();

            heap.Insert(5);
            heap.Clear();
            Assert.AreEqual(0, heap.Size);
        }
Exemple #22
0
 public int eval(IDictionary <String, int> tbl, IHeap <int> h)
 {
     if (tbl.containsKey(id))
     {
         return((int)tbl[id]);
     }
     throw new UninitializedVariableException();
 }
Exemple #23
0
        internal static void UnpackSerializedHeap(XElement heapNode, IHeap <XElement> heap)
        {
            var elementsEnumerator = heapNode.Elements().GetEnumerator();

            while (elementsEnumerator.MoveNext())
            {
                heap.Add(XMLUtility.GuidOfAttribute(elementsEnumerator.Current), elementsEnumerator.Current);
            }
        }
Exemple #24
0
 public PrgState()
 {
     id              = 0;
     exeStack        = null;
     symTable        = null;
     output          = null;
     originalProgram = null;
     heap            = null;
 }
Exemple #25
0
        public void SizeTest(IHeap <int> heap)
        {
            var tmpLst   = new List <int>(TestList);
            var expected = tmpLst.Count;
            var result   = heap.Size();

            Console.WriteLine("Expect:" + expected + " Result:" + result);
            Assert.AreEqual(expected, result);
        }
Exemple #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriorityQueue{TKey, TValue}"/> class.
        /// </summary>
        /// <param name="initialCapacity">The initial queue capacity.</param>
        /// <param name="maximumSize">The maximum recommended number of elements in the queue. The actual number of elements might be larger.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="maximumSize"/> is zero or less.
        /// </exception>
        public PriorityQueue(int initialCapacity, int maximumSize)
        {
            if (maximumSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maximumSize), maximumSize, "The maximum size of priority queue must be greater than zero.");
            }

            this.heap = new BinaryHeap <TKey, TValue>(initialCapacity, maximumSize);
        }
Exemple #27
0
 public PrgState(MyIStack <IStmt> stk, Stack <MyIDictionary <MyMap> > symtbl, MyIList <int> otp, IStmt crtstm, IHeap <HMap> h)
 {
     id++;
     exeStack        = stk;
     symTable        = symtbl;
     output          = otp;
     originalProgram = crtstm;
     exeStack.Push(crtstm);
     heap = h;
 }
 public ProgramState(IMyStack<IMyStatement> executionStack, IMyDictionary<string, int> myDictionary, IMyList<string> output, IHeap<int, int> heap, IMyStatement originalProgram)
 {
     this.executionStack = executionStack;
     this.myDictionary = myDictionary;
     this.output = output;
     this.originalProgram = originalProgram;
     this.executionStack.push(originalProgram);
     this.heap = heap;
     this.stateId = globalStateId++;
 }
Exemple #29
0
        public HeapServer(IHeap heap, TcpServer tcpServer)
        {
            if (heap == null)
                throw new ArgumentNullException("heap");
            if (tcpServer == null)
                throw new ArgumentNullException("tcpServer");

            Heap = heap;
            TcpServer = tcpServer;
        }
Exemple #30
0
        public void GetMinTest(IHeap <int> heap, bool isMin)
        {
            var tmpLst = new List <int>(TestList);

            Console.WriteLine("isMin:" + isMin);
            var expected = isMin ? tmpLst.Min() : tmpLst.Max();
            var result   = heap.GetMin().Value;

            Console.WriteLine("Expect:" + expected + " Result:" + result);
            Assert.AreEqual(expected, result);
        }
Exemple #31
0
        void AssertMinToMax(IHeap <int> minHeap)
        {
            int currentValue = minHeap.Pop();

            for (int i = 1; i < minHeap.Count; i++)
            {
                int nextValue = minHeap.Pop();
                Assert.IsTrue(currentValue <= nextValue);
                currentValue = nextValue;
            }
        }
Exemple #32
0
 /// <summary>
 /// Creates a new priority queue.
 /// </summary>
 /// <param name="maxBased">Weather this PriorityQueue will order based on highest value or lowest value</param>
 /// <param name="size">The starting size of this queue</param>
 public PriorityQueue(bool maxBased, int size = 10)
 {
     if (maxBased)
     {
         _heap = new MaxHeap <QueueNode <T> >(size);
     }
     else
     {
         _heap = new MinHeap <QueueNode <T> >(size);
     }
 }
Exemple #33
0
        void AssertMaxToMin(IHeap <int> maxHeap)
        {
            int currentValue = maxHeap.Pop();

            for (int i = 1; i < maxHeap.Count; i++)
            {
                int nextValue = maxHeap.Pop();
                Assert.IsTrue(currentValue >= nextValue);
                currentValue = nextValue;
            }
        }
Exemple #34
0
 public int eval(IDictionary<String, int> tbl, IHeap<int> h)
 {
     if (op == '+') return (e1.eval(tbl, h) + e2.eval(tbl, h));
     if (op == '-') return (e1.eval(tbl, h) - e2.eval(tbl, h));
     if (op == '*') return (e1.eval(tbl, h) * e2.eval(tbl, h));
     if (op == '/') {
         if (e2.eval (tbl, h) == 0)
             throw new DivisionByZeroException ();
         return (e1.eval (tbl, h) / e2.eval (tbl, h));
     }
     return 0;
 }
Exemple #35
0
        public WTree(IHeap heap)
        {
            if (heap == null)
                throw new NullReferenceException("heap");

            this.heap = heap;

            if (heap.Exists(HANDLE_SETTINGS))
            {
                //create root branch with dummy handle
                RootBranch = new Branch(this, NodeType.Leaf, 0);

                //read settings - settings will set the RootBranch.NodeHandle
                using (MemoryStream ms = new MemoryStream(heap.Read(HANDLE_SETTINGS)))
                    Settings.Deserialize(this, ms);

                //read scheme
                using (MemoryStream ms = new MemoryStream(heap.Read(HANDLE_SCHEME)))
                    scheme = Scheme.Deserialize(new BinaryReader(ms));

                ////load branch cache
                //using (MemoryStream ms = new MemoryStream(Heap.Read(HANDLE_ROOT)))
                //    RootBranch.Cache.Load(this, new BinaryReader(ms));
                isRootCacheLoaded = false;
            }
            else
            {
                //obtain reserved handles
                var handle = heap.ObtainNewHandle();
                if (handle != HANDLE_SETTINGS)
                    throw new Exception("Logical error.");

                scheme = new WaterfallTree.Scheme();
                handle = heap.ObtainNewHandle();
                if (handle != HANDLE_SCHEME)
                    throw new Exception("Logical error.");

                handle = heap.ObtainNewHandle();
                if (handle != HANDLE_ROOT)
                    throw new Exception("Logical error.");

                handle = heap.ObtainNewHandle();
                if (handle != HANDLE_RESERVED)
                    throw new Exception("Logical error.");

                RootBranch = new Branch(this, NodeType.Leaf); //the constructor will invoke Heap.ObtainHandle()

                isRootCacheLoaded = true;
            }

            CacheThread = new Thread(DoCache);
            CacheThread.Start();
        }
 /**
  * Evaluates the expression
  * For simplicity the result will be converted to int
  * @param table The table of values in case of a variable
  * @return int result
  */
 public int eval(IMyDictionary<string, int> table, IHeap<int, int> heap)
 {
     switch (operatorType)
     {
         case OperatorsEnum.ADD:
             return (int)(firstExpression.eval(table, heap) + secondExpression.eval(table, heap));
         case OperatorsEnum.SUBSTRACT:
             return (int)(firstExpression.eval(table, heap) - secondExpression.eval(table, heap));
         case OperatorsEnum.MULTIPLY:
             return (int)(firstExpression.eval(table, heap) * secondExpression.eval(table, heap));
         case OperatorsEnum.DIVIDE:
             return (int)(firstExpression.eval(table, heap) + secondExpression.eval(table, heap));
         default:
             return int.MaxValue;
     }
 }
        /**
         * Evaluates the expression
         * For simplicity the result will be converted to int
         *
         * @param table The table of values in case of a variable
         * @return int result
         */
        public int eval(IMyDictionary<string, int> table, IHeap<int, int> heap)
        {
            bool firstBoolean;
            bool secondBoolean;

            if (firstExpression.eval(table, heap) == 0)
            {
                firstBoolean = false;
            }
            else
            {
                firstBoolean = true;
            }

            if (firstExpression.eval(table, heap) == 0)
            {
                secondBoolean = false;
            }
            else
            {
                secondBoolean = true;
            }

            switch (operatorType)
            {
                case OperatorsEnum.AND:
                    if (firstBoolean && secondBoolean)
                    {
                        return 1;
                    }
                    return 0;
                case OperatorsEnum.OR:
                    if (firstBoolean || secondBoolean)
                    {
                        return 1;
                    }
                    return 0;
                case OperatorsEnum.NOT:
                    if (!firstBoolean)
                    {
                        return 1;
                    }
                    return 0;
                default:
                    return int.MinValue;
            }
        }
 /**
  * Evaluates the expression
  * For simplicity the result will be converted to int
  * @param table The table of values in case of a variable
  * @return int result
  */
 public int eval(IMyDictionary<string, int> table, IHeap<int, int> heap)
 {
     switch (operatorType)
     {
         case OperatorsEnum.LESS:
             if (firstExpression.eval(table, heap) < secondExpression.eval(table, heap))
             {
                 return 1;
             }
             return 0;
         case OperatorsEnum.LESS_EQUAL:
             if (firstExpression.eval(table, heap) <= secondExpression.eval(table, heap))
             {
                 return 1;
             }
             return 0;
         case OperatorsEnum.GRATER_EQUAL:
             if (firstExpression.eval(table, heap) >= secondExpression.eval(table, heap))
             {
                 return 1;
             }
             return 0;
         case OperatorsEnum.GRATER:
             if (firstExpression.eval(table, heap) > secondExpression.eval(table, heap))
             {
                 return 1;
             }
             return 0;
         case OperatorsEnum.EQUAL:
             if (firstExpression.eval(table, heap) == secondExpression.eval(table, heap))
             {
                 return 1;
             }
             return 0;
         case OperatorsEnum.DIFFERENT:
             if (firstExpression.eval(table, heap) != secondExpression.eval(table, heap))
             {
                 return 1;
             }
             return 0;
         default:
             return int.MinValue;
     }
 }
Exemple #39
0
 public int eval(IDictionary<String, int> tbl, IHeap<int> h)
 {
     switch (cmp) {
     case "&&":
         if (e1.eval(tbl, h) != 0 && e2.eval(tbl, h) != 0)
             return 1;
         else
             return 0;
     case "||":
         if (e1.eval(tbl, h) != 0 || e2.eval(tbl, h) != 0)
             return 1;
         else
             return 0;
     case "!":
         if (e1.eval(tbl, h) == 0)
             return 1;
         else
             return 0;
     }
     return 0;
 }
Exemple #40
0
        public int eval(IDictionary<String, int> tbl, IHeap<int> h)
        {
            if (cmp == "<") {
                if (e1.eval(tbl, h) < e2.eval(tbl, h))
                    return 1;
                else
                    return 0;
            } else if (cmp == "<="){
                if(e1.eval(tbl, h) <= e2.eval(tbl, h))
                    return 1;
                else
                    return 0;
            } else if (cmp == "=="){
                if(e1.eval(tbl, h) == e2.eval(tbl, h))
                    return 1;
                else
                    return 0;
            } else if (cmp == "!="){
                if(e1.eval(tbl, h) != e2.eval(tbl, h))
                    return 1;
                else
                    return 0;
            } else if (cmp == ">"){
                if(e1.eval(tbl, h) > e2.eval(tbl, h))
                    return 1;
                else
                    return 0;
            } else if (cmp == ">="){
                if(e1.eval(tbl, h) <= e2.eval(tbl, h))
                    return 1;
                else
                    return 0;
            }

            return 0;
        }
Exemple #41
0
 public int eval(IDictionary<String, int> tbl, IHeap<int> h)
 {
     return nr;
 }
        /// <summary>
        /// Returns the specified number of parses or fewer for the specified tokens.
        /// </summary>
        /// <param name="tokens">A parse containing the tokens with a single parent node.</param>
        /// <param name="numParses">The number of parses desired.</param>
        /// <returns>The specified number of parses for the specified tokens.</returns>
        /// <remarks>
        /// The nodes within the returned parses are shared with other parses and therefore their 
        /// parent node references will not be consistent with their child node reference. 
        /// <see cref="SharpNL.Parser.Parse.Parent"/> can be used to make the parents consistent with a 
        /// particular parse, but subsequent calls to this property can invalidate the results of earlier
        /// calls.
        /// </remarks>
        public Parse[] Parse(Parse tokens, int numParses) {
            if (createDerivationString)
                tokens.Derivation = new StringBuilder();

            odh.Clear();
            ndh.Clear();
            completeParses.Clear();
            var derivationStage = 0; //derivation length
            var maxDerivationLength = 2*tokens.ChildCount + 3;
            odh.Add(tokens);
            Parse guess = null;
            double minComplete = 2;
            double bestComplete = -100000; //approximating -infinity/0 in ln domain

            while (odh.Size() > 0 && 
                  (completeParses.Size() < M || odh.First().Probability < minComplete) &&
                   derivationStage < maxDerivationLength) {

                ndh = new ListHeap<Parse>(K);

                var derivationRank = 0;
                // foreach derivation
                for (var pi = odh.GetEnumerator(); pi.MoveNext() && derivationRank < K; derivationRank++) {
                    var tp = pi.Current;

                    //TODO: Need to look at this for K-best parsing cases
                    /*
                     if (tp.getProb() < bestComplete) { //this parse and the ones which follow will never win, stop advancing.
                     break;
                     }
                     */

                    if (guess == null && derivationStage == 2) {
                        guess = tp;
                    }
#if DEBUG
                    if (debugOn) {
                        Console.Out.WriteLine(derivationStage + " " + derivationRank + " " + tp.Probability);
                        Console.Out.WriteLine(tp.ToString());
                        Console.Out.WriteLine();
                    }
#endif

                    Parse[] nd;

                    if (derivationStage == 0) {
                        nd = AdvanceTags(tp);

                    } else if (derivationStage == 1) {
                        nd = AdvanceChunks(tp, ndh.Size() < K ? bestComplete : ndh.Last().Probability);
                    } else {
                        // i > 1
                        nd = AdvanceParses(tp, Q);
                    }

                    if (nd != null) {
                        for (int k = 0, kl = nd.Length; k < kl; k++) {

                            if (nd[k].Complete) {
                                AdvanceTop(nd[k]);
                                if (nd[k].Probability > bestComplete) {
                                    bestComplete = nd[k].Probability;
                                }
                                if (nd[k].Probability < minComplete) {
                                    minComplete = nd[k].Probability;
                                }
                                completeParses.Add(nd[k]);
                            } else {
                                ndh.Add(nd[k]);
                            }
                        }
                    } else {
                        if (ReportFailedParse) {
                            Console.Error.WriteLine("Couldn't advance parse " + derivationStage + " stage " +
                                                    derivationRank + "!\n");
                        }
                        AdvanceTop(tp);
                        completeParses.Add(tp);
                    }
                }
                derivationStage++;
                odh = ndh;
            }
            if (completeParses.Size() == 0) {
                if (ReportFailedParse)
                    Console.Error.WriteLine("Couldn't find parse for: " + tokens);
                //Parse r = (Parse) odh.first();
                //r.show();
                //System.out.println();
                return new[] {guess};
            }
            if (numParses == 1) {
                return new[] {completeParses.First()};
            }
            var topParses = new List<Parse>();
            while (!completeParses.IsEmpty() && topParses.Count < numParses) {
                var tp = completeParses.Extract();
                topParses.Add(tp);
                //parses.remove(tp);
            }
            return topParses.ToArray();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractBottomUpParser"/>.
 /// </summary>
 /// <param name="tagger">The pos-tagger that the parser uses.</param>
 /// <param name="chunker">The chunker that the parser uses to chunk non-recursive structures.</param>
 /// <param name="headRules">The head rules for the parser.</param>
 /// <param name="beamSize">Size of the beam.</param>
 /// <param name="advancePercentage">The advance percentage.</param>
 protected AbstractBottomUpParser(IPOSTagger tagger, IChunker chunker, AbstractHeadRules headRules, int beamSize,
     double advancePercentage) {
     this.tagger = tagger;
     this.chunker = chunker;
     M = beamSize;
     K = beamSize;
     Q = advancePercentage;
     ReportFailedParse = true;
     this.headRules = headRules;
     punctSet = headRules.PunctuationTags;
     odh = new ListHeap<Parse>(K);
     ndh = new ListHeap<Parse>(K);
     completeParses = new ListHeap<Parse>(K);
 }
Exemple #44
0
 public int eval(IDictionary<String, int> tbl, IHeap<int> h)
 {
     if (tbl.containsKey(id)) return (int) tbl[id];
     throw new UninitializedVariableException ();
 }
Exemple #45
0
 public HeapServer(IHeap heap, int port = 7183)
     : this(heap, new TcpServer(port))
 {
 }
Exemple #46
0
 public int eval(IMyDictionary<string, int> table, IHeap<int, int> heap)
 {
     return heap.lookUp(table.lookUp(variableName));
 }
Exemple #47
0
 public void createProgram(IMyStack<IMyStatement> mExecutionStack, IMyDictionary<String, int> myDictionary, IMyList<String> mOutput, IHeap<int, int> heap, IMyStatement mInitialProgram)
 {
     programStateList.Add(new ProgramState(mExecutionStack, myDictionary, mOutput, heap, mInitialProgram));
 }
Exemple #48
0
 public int eval(IDictionary<String, int> tbl, IHeap<int> h)
 {
     Console.WriteLine("Input a number: ");
     return Convert.ToInt32(Console.ReadLine());
 }
 public void setHeap(IHeap<int, int> heap)
 {
     this.heap = heap;
 }
 public int eval(IDictionary<String, int> tbl, IHeap<int> heap)
 {
     int address = tbl[id];
     return heap[address];
 }
 public int eval(IMyDictionary<string, int> table, IHeap<int, int> heap)
 {
     return number;
 }
Exemple #52
0
 public static IStorageEngine FromHeap(IHeap heap)
 {
     return new StorageEngine(heap);
 }
Exemple #53
0
 public void Initialize()
 {
     this.comparision = (x, y) => y.CompareTo(x);
     this.heap = new BinaryHeap<int>(comparision);
 }
 /**
  * Evaluate the variable by getting its value from the Table
  * @param table Table of values
  * @return int value
  */
 public int eval(IMyDictionary<string, int> table, IHeap<int, int> heap)
 {
     return table.lookUp(name);
 }