Example #1
0
        public void TestFirstAndLast()
        {
            BTreeDictionary <int, string> data = new BTreeDictionary <int, string>(Comparer);

            data.Add(1, "a");
            data.Add(2, "b");
            data.Add(3, "c");
            data.Add(4, "d");
            data.Add(5, "e");

            Assert.AreEqual(1, data.First().Key);
            Assert.AreEqual("a", data.First().Value);
            data.Remove(1);
            Assert.AreEqual(2, data.First().Key);
            Assert.AreEqual("b", data.First().Value);

            Assert.AreEqual(5, data.Last().Key);
            Assert.AreEqual("e", data.Last().Value);
            data.Remove(5);
            Assert.AreEqual(4, data.Last().Key);
            Assert.AreEqual("d", data.Last().Value);

            data.Remove(4);
            data.Remove(3);

            KeyValuePair <int, string> kv;

            Assert.IsTrue(data.TryGetLast(out kv));
            Assert.IsTrue(data.TryGetFirst(out kv));
            data.Remove(2);
            Assert.IsFalse(data.TryGetLast(out kv));
            Assert.IsFalse(data.TryGetFirst(out kv));

            try
            {
                data.First();
                Assert.Fail("Should raise InvalidOperationException");
            }
            catch (InvalidOperationException)
            {
            }
            try
            {
                data.Last();
                Assert.Fail("Should raise InvalidOperationException");
            }
            catch (InvalidOperationException)
            {
            }
        }
Example #2
0
 internal void ItemsRemoved(IList newItems)
 {
     foreach (var item in newItems.Cast <ObjectTreeItem <T> >())
     {
         objectToObjectItems.Remove(item.InternalObject);
     }
 }
        /// <summary>
        /// Inserts blanks entries before the current location.
        /// The current location becomes the first inserted item.
        /// </summary>
        /// <param name="quantity">Number of entries to insert.</param>
        public virtual void Insert(int quantity = 1)
        {
            // Shifts current indices
            if (_fonts.MoveLast())
            {
                do
                {
                    if (_fonts.CurrentKey >= _index)
                    {
                        Font currentFont = _fonts.CurrentValue;
                        int  newKey      = _fonts.CurrentKey + quantity;
                        _fonts.Remove();
                        _fonts.Add(newKey, currentFont);
                    }
                } while (_fonts.MovePrevious());
            }

            // Adds blank spaces
            for (int i = _index; i < _index + quantity; i++)
            {
                _fonts.Add(_index, null);
            }
        }
Example #4
0
        public Block?EnqueueJumpTarget(Address addrSrc, Address addrDest, Procedure proc, ProcessorState state)
        {
            Procedure procDest;
            Block?    block = FindExactBlock(addrDest);

            if (block == null)
            {
                // Target wasn't a block before. Make sure it exists.
                block = FindContainingBlock(addrDest);
                if (block != null)
                {
                    block = SplitBlock(block, addrDest);
                }
                else
                {
                    var label = Program.NamingPolicy.BlockName(addrDest);
                    block = AddBlock(addrDest, proc, label);
                }

                if (proc == block.Procedure)
                {
                    // Easy case: split a block in our own procedure.
                    var wi = CreateBlockWorkItem(addrDest, proc, state);
                    procQueue.Enqueue(PriorityJumpTarget, wi);
                }
                else if (IsBlockLinearProcedureExit(block))
                {
                    block = CloneBlockIntoOtherProcedure(block, proc);
                }
                else
                {
                    // We just created a block in a foreign procedure.
                    blocks.Remove(addrDest);
                    block.Procedure.RemoveBlock(block);
                    procDest = Program.EnsureProcedure(block.Procedure.Architecture, addrDest, null);
                    EnqueueProcedure(block.Procedure.Architecture, addrDest);
                    var blockThunk = CreateCallRetThunk(addrSrc, proc, procDest);
                    var wi         = CreatePromoteWorkItem(addrDest, block, procDest);
                    procQueue.Enqueue(PriorityBlockPromote, wi);
                    block = blockThunk;
                }
            }
            else if (block.Procedure != proc)
            {
                // Jumped to a block with a different procedure than the
                // current one. Was the jump to the entry of an existing procedure?
                if (Program.Procedures.TryGetValue(addrDest, out procDest))
                {
                    if (procDest == proc)
                    {
                        proc.Signature.StackDelta    = block.Procedure.Signature.StackDelta;
                        proc.Signature.FpuStackDelta = block.Procedure.Signature.FpuStackDelta;
                        var wi = CreatePromoteWorkItem(addrDest, block, procDest);
                        procQueue.Enqueue(PriorityBlockPromote, wi);
                    }
                    else
                    {
                        // We jumped to the entry of a different procedure.
                        block = CreateCallRetThunk(addrSrc, proc, procDest);
                    }
                }
                else
                {
                    // Jumped into the middle of another procedure. Is it worth
                    // promoting the destination block to a new procedure?
                    if (IsBlockLinearProcedureExit(block))
                    {
                        // No, just clone the block into the new procedure.
                        block = CloneBlockIntoOtherProcedure(block, proc);
                    }
                    else
                    {
                        // We jumped into a pre-existing block of another
                        // procedure which was hairy enough that we need to
                        // promote the block to a new procedure.
                        procDest = Program.EnsureProcedure(proc.Architecture, addrDest, null);
                        var blockNew = CreateCallRetThunk(addrSrc, proc, procDest);
                        EstablishInitialState(addrDest, Program.Architecture.CreateProcessorState(), procDest);
                        procDest.ControlGraph.AddEdge(procDest.EntryBlock, block);
                        InjectProcedureEntryInstructions(addrDest, procDest);
                        var wi = CreatePromoteWorkItem(addrDest, block, procDest);
                        procQueue.Enqueue(PriorityBlockPromote, wi);
                        return(blockNew);
                    }
                }
            }
            return(block);
        }
        void SequencedTest(int start, int incr, int stop, string name)
        {
            int          count = Math.Abs(start - stop) / Math.Abs(incr);
            const string myTestValue1 = "T1", myTestValue2 = "t2";
            string       test;

            BTreeDictionary <int, string> data = new BTreeDictionary <int, string>(Comparer);
            Stopwatch time = new Stopwatch();

            time.Start();
            //large order-forward
            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryAdd(i, myTestValue1))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} insert  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryGetValue(i, out test) || test != myTestValue1)
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} seek    {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryUpdate(i, myTestValue2))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} modify  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.TryGetValue(i, out test) || test != myTestValue2)
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} seek#2  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            int tmpCount = 0;

            foreach (KeyValuePair <int, string> tmp in data)
            {
                if (tmp.Value != myTestValue2)
                {
                    throw new ApplicationException();
                }
                else
                {
                    tmpCount++;
                }
            }
            if (tmpCount != count)
            {
                throw new ApplicationException();
            }

            Trace.TraceInformation("{0} foreach {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!data.Remove(i))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} delete  {1} in {2}", name, count, time.ElapsedMilliseconds);

            for (int i = start; i != stop; i += incr)
            {
                if (data.TryGetValue(i, out test))
                {
                    throw new ApplicationException();
                }
            }
        }