Пример #1
0
        public void Setup()
        {
            emptyList = new CircularLinkedList <int>();
            oneList   = new CircularLinkedList <int>(new int[] { 42 });
            twoList   = new CircularLinkedList <int>(new int[] { 37, 51 });
            threeList = new CircularLinkedList <int>();

            // 2 3 4
            threeList.AddLast(3);
            threeList.AddLast(4);
            threeList.AddFirst(2);

            string[] tmpStrings = new string[] { "foo", "bar", "baz" };
            // FIXME workaround for 74953

            List <string> workaround = new List <string>();

            foreach (string s in tmpStrings)
            {
                workaround.Add(s);
            }

            // strings = new CircularLinkedList <string> (tmpStrings);
            stringList = new CircularLinkedList <string>(workaround);
        }
Пример #2
0
        /// <summary>
        /// Removes nodes from the arguments list and inserts them at the end of the target list.
        /// </summary>
        /// <param name="srcFirst">The first node in the source list.</param>
        /// <param name="srcLast">The last node in the source list.</param>
        public void SpliceLast(CircularLinkedListNode <T> srcFirst, CircularLinkedListNode <T> srcLast)
        {
            if (srcFirst == null)
            {
                throw new ArgumentNullException("srcFirst");
            }
            if (srcLast == null)
            {
                throw new ArgumentNullException("srcLast");
            }
            if (srcFirst.List != srcLast.List)
            {
                throw new InvalidOperationException("source nodes not in same list");
            }
            CircularLinkedList <T>     srcList    = srcFirst.List;
            CircularLinkedListNode <T> terminator = srcLast.Next;
            CircularLinkedListNode <T> node       = srcFirst;

            do
            {
                CircularLinkedListNode <T> nextNode = node.Next;
                srcList.Remove(node);
                this.AddLast(node);
                node = nextNode;
            }while (node != terminator);
        }
Пример #3
0
        /* FIXME: disabled pending fix for #75299
         * [Test]
         */
        public void EnumeratorSerializationTest()
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream();

            CircularLinkedList <int> .Enumerator e = threeList.GetEnumerator();
            formatter.Serialize(stream, e);

            stream.Position = 0;
            object deserialized = formatter.Deserialize(stream);

            Assert.IsTrue(deserialized is CircularLinkedList <int> .Enumerator);

            CircularLinkedList <int> .Enumerator d = (CircularLinkedList <int> .Enumerator)deserialized;

            int[] values = { 2, 3, 4 };
            int   i      = 0;

            while (d.MoveNext())
            {
                Assert.AreEqual(values[i], d.Current);
                i++;
            }
            Assert.AreEqual(3, i);
        }
Пример #4
0
 internal Enumerator(SerializationInfo info, StreamingContext context)
 {
     si      = info;
     list    = (CircularLinkedList <T>)si.GetValue(ListKey, typeof(CircularLinkedList <T>));
     index   = si.GetInt32(IndexKey);
     version = si.GetUInt32(VersionKey);
     current = null;
 }
Пример #5
0
 internal void InsertBetween(CircularLinkedListNode <T> previousNode, CircularLinkedListNode <T> nextNode, CircularLinkedList <T> list)
 {
     previousNode.forward = this;
     nextNode.back        = this;
     this.forward         = nextNode;
     this.back            = previousNode;
     this.container       = list;
 }
Пример #6
0
        internal void Detach()
        {
            back.forward = forward;
            forward.back = back;

            forward   = back = null;
            container = null;
        }
Пример #7
0
 public void Dispose()
 {
     if (list == null)
     {
         throw new ObjectDisposedException(null);
     }
     current = null;
     list    = null;
 }
Пример #8
0
 internal CircularLinkedListNode(CircularLinkedList <T> list, T value, CircularLinkedListNode <T> previousNode, CircularLinkedListNode <T> nextNode)
 {
     container            = list;
     item                 = value;
     this.back            = previousNode;
     this.forward         = nextNode;
     previousNode.forward = this;
     nextNode.back        = this;
 }
Пример #9
0
            internal Enumerator(CircularLinkedList <T> parent)
            {
#if !NET_2_1
                si = null;
#endif
                this.list = parent;
                current   = null;
                index     = -1;
                version   = parent.version;
            }
Пример #10
0
        public void ListSerializationTest()
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream();

            formatter.Serialize(stream, threeList);

            stream.Position = 0;
            object deserialized = formatter.Deserialize(stream);

            Assert.IsTrue(deserialized is CircularLinkedList <int>);

            CircularLinkedList <int> dlist = deserialized as CircularLinkedList <int>;

            int[] values = { 2, 3, 4 };
            int   i      = 0;

            foreach (int value in dlist)
            {
                Assert.AreEqual(values[i], value);
                i++;
            }
            Assert.AreEqual(3, i);
        }
Пример #11
0
 internal void SelfReference(CircularLinkedList <T> list)
 {
     forward   = this;
     back      = this;
     container = list;
 }
Пример #12
0
 internal CircularLinkedListNode(CircularLinkedList <T> list, T value)
 {
     container = list;
     item      = value;
     this.back = this.forward = this;
 }