Esempio n. 1
0
        public void Test_ColaOrderedDictionary_Remove()
        {
            const int N = 100;

            // add a bunch of random values
            var rnd  = new Random();
            int seed = 1333019583;            // rnd.Next();

            Console.WriteLine("Seed " + seed);
            rnd = new Random(seed);

            var cola = new ColaOrderedDictionary <int, string>();
            var list = new List <int>();

            int x = 0;

            for (int i = 0; i < N; i++)
            {
                x += (1 + rnd.Next(10));
                string s = "value of " + x;

                cola.Add(x, s);
                list.Add(x);
            }
            Assert.That(cola.Count, Is.EqualTo(N));

            foreach (var item in list)
            {
                Assert.That(cola.ContainsKey(item), "{0} is missing", item);
            }

            cola.Debug_Dump();

            // now start removing items one by one
            while (list.Count > 0)
            {
                int p = rnd.Next(list.Count);
                x = list[p];
                list.RemoveAt(p);

                bool res = cola.Remove(x);
                if (!res)
                {
                    cola.Debug_Dump();
                }
                Assert.That(res, Is.True, "Remove({0}) failed", x);

                Assert.That(cola.Count, Is.EqualTo(list.Count), "After removing {0}", x);
            }

            cola.Debug_Dump();
        }
Esempio n. 2
0
        /// <summary>Adds a range to teh clear list of this transaction</summary>
        /// <remarks>Must be called with m_lock taken</remarks>
        private void AddClearCommand_NeedsLocking(FdbKeyRange range)
        {
            // merge the cleared range with the others
            m_clears.Mark(range.Begin, range.End);

            // remove all writes that where in this range
            var keys = m_writes.FindBetween(range.Begin, true, range.End, false).ToList();

            if (keys.Count > 0)
            {
                foreach (var key in keys)
                {
                    m_writes.Remove(key);
                }
            }
        }
		public void Test_ColaOrderedDictionary_Remove()
		{
			const int N = 100;

			// add a bunch of random values
			var rnd = new Random();
			int seed = 1333019583;// rnd.Next();
			Console.WriteLine("Seed " + seed);
			rnd = new Random(seed);

			var cola = new ColaOrderedDictionary<int, string>();
			var list = new List<int>();

			int x = 0;
			for (int i = 0; i < N; i++)
			{
				x += (1 + rnd.Next(10));
				string s = "value of " + x;

				cola.Add(x, s);
				list.Add(x);
			}
			Assert.That(cola.Count, Is.EqualTo(N));

			foreach(var item in list)
			{
				Assert.That(cola.ContainsKey(item), "{0} is missing", item);
			}

			cola.Debug_Dump();

			// now start removing items one by one
			while(list.Count > 0)
			{
				int p = rnd.Next(list.Count);
				x = list[p];
				list.RemoveAt(p);

				bool res = cola.Remove(x);
				if (!res) cola.Debug_Dump();
				Assert.That(res, Is.True, "Remove({0}) failed", x);

				Assert.That(cola.Count, Is.EqualTo(list.Count), "After removing {0}", x);
			}

			cola.Debug_Dump();

		}