예제 #1
0
        public void EmptyLeafTest()
        {
            var t  = RedBlackSet <string> .EmptyTree;
            var x1 = RedBlackSet <string> .Insert("C", t);

            Assert.AreEqual("(B: C)", DumpSet(x1));
        }
예제 #2
0
        private void WriteAction()
        {
            var total = 0;

            for (var i = 0; i < 2 * Count; i++)
            {
                var word = NextWord(1);
                while (true)
                {
                    total++;
                    var localCopy = _set;
                    Thread.MemoryBarrier();
                    var newSet = RedBlackSet <string> .Insert(word, localCopy);

                    var oldSet = Interlocked.CompareExchange(ref _set, newSet, localCopy);
                    if (ReferenceEquals(localCopy, oldSet))
                    {
                        break;
                    }
                }
            }

            Console.WriteLine("Write Task={0}, Thread={1} : {2} average",
                              Task.CurrentId, Thread.CurrentThread.ManagedThreadId, 2.0 * Count / total);
        }
예제 #3
0
        public void DuplicateRootMemberTest()
        {
            var t  = RedBlackSet <string> .EmptyTree;
            var x1 = RedBlackSet <string> .Insert("C", t);

            var x2 = RedBlackSet <string> .Insert("C", x1);

            Assert.AreEqual("(B: C)", DumpSet(x2));
            Assert.AreNotSame(x1, x2);
        }
예제 #4
0
        public void MemberTest()
        {
            var t  = RedBlackSet <string> .EmptyTree;
            var x1 = RedBlackSet <string> .Insert("C", t);

            var x2 = RedBlackSet <string> .Insert("B", x1);

            Assert.IsTrue(RedBlackSet <string> .Member("B", x2));
            Assert.IsFalse(RedBlackSet <string> .Member("A", x2));
            Assert.IsFalse(RedBlackSet <string> .Member("D", x2));
        }
예제 #5
0
 private void WriteAction()
 {
     for (var i = 0; i < 2 * Count; i++)
     {
         var word = NextWord(1);
         lock (_lockObject)
         {
             _set = RedBlackSet <string> .Insert(word, _set);
         }
     }
 }
예제 #6
0
        public void DuplicateLeafMemberTest()
        {
            var empty = RedBlackSet <string> .EmptyTree;
            var a     = RedBlackSet <string> .Insert("A", empty);

            var b = RedBlackSet <string> .Insert("B", a);

            var c1 = RedBlackSet <string> .Insert("C", b);

            Assert.AreEqual("(B: (B: A) B (B: C))", DumpSet(c1));
            var c2 = RedBlackSet <string> .Insert("C", c1);

            Assert.AreEqual("(B: (B: A) B (B: C))", DumpSet(c2));
            Assert.AreNotSame(c1, c2);
        }
예제 #7
0
 private void WriteAction()
 {
     for (var i = 0; i < 2 * Count; i++)
     {
         var word = NextWord(1);
         _lockObject.EnterWriteLock();
         try
         {
             _set = RedBlackSet <string> .Insert(word, _set);
         }
         finally
         {
             _lockObject.ExitWriteLock();
         }
     }
 }
예제 #8
0
        public void BalanceTest6()
        {
            const string data = "y z x";
            var          t    = data.Split().Aggregate(RedBlackSet <string> .EmptyTree, (current, word) => RedBlackSet <string> .Insert(word, current));

            Assert.AreEqual("(B: (R: x) y (R: z))", DumpSet(t));
        }