private IIterator <ObjectId> SwapFetchQueue()
        {
            var r = new LinkedListIterator <ObjectId>(_workQueue);

            _workQueue = new LinkedList <ObjectId>();
            return(r);
        }
Ejemplo n.º 2
0
        public void RemoveAtIndex(int index)
        {
            if (index > Length - 1)
            {
                throw new IndexOutOfRangeException();
            }
            else if (index == Length - 1)
            {
                Pop();
            }
            else if (index == 0)
            {
                RemoveFirst();
            }
            else
            {
                LinkedListIterator <T> iter = this.Iterator();
                while (iter.CurrentIndex < index)
                {
                    iter.Next();
                }

                iter.Remove();

                Length--;
            }
        }
Ejemplo n.º 3
0
        public void EmptyList()
        {
            var list = new LinkedList <int>();
            var iter = new LinkedListIterator <int>(list);

            AssertEndOfListHasBeenReached(iter);
            AssertHelper.Throws <IndexOutOfRangeException>(iter.remove);
        }
Ejemplo n.º 4
0
        public void EmptyList()
        {
            var list = new LinkedList<int>();
            var iter = new LinkedListIterator<int>(list);

            AssertEndOfListHasBeenReached(iter);
            AssertHelper.Throws<IndexOutOfRangeException>(iter.remove);
        }
Ejemplo n.º 5
0
        public T Get(int index)
        {
            LinkedListIterator <T> itr = Iterator();
            T item = default(T);

            while (itr.CurrentIndex < index && itr.HasNext())
            {
                item = itr.Next();
            }
            return(item);
        }
Ejemplo n.º 6
0
        public void Remove(T item)
        {
            LinkedListIterator <T> iter = this.Iterator();

            while (iter.HasNext())
            {
                if (iter.Next().Equals(item))
                {
                    iter.Remove();
                    Length--;
                }
            }
        }
Ejemplo n.º 7
0
        // Insert in sorted order.
        // x is the item to insert.
        public void Insert(AnyType x)
        {
            LinkedListIterator <AnyType> prev = Zeroth( );
            LinkedListIterator <AnyType> curr = First( );

            while (curr.IsValid( ) && x.CompareTo(curr.Retrieve( )) > 0)
            {
                prev.Advance( );
                curr.Advance( );
            }

            base.Insert(x, prev);
        }
Ejemplo n.º 8
0
        public T[] ToArray()
        {
            T[] array = new T[Length];

            LinkedListIterator <T> iter = this.Iterator();
            int index = 0;

            while (iter.HasNext())
            {
                array[index] = iter.Next();
                index++;
            }
            return(array);
        }
Ejemplo n.º 9
0
 private Event PeekEvent()
 {
     return(locker.Synchronized(() =>
     {
         LinkedListIterator <Event> i = iterator++;
         Event message = i.Value;
         LinkedListNode <Event> node = i.Node;
         if (node != null)
         {
             events.Remove(node);
             iterator.Remove(node);
         }
         return message;
     }));
 }
Ejemplo n.º 10
0
        public bool Contains(T item)
        {
            bool contains = false;
            LinkedListIterator <T> iter = this.Iterator();

            while (iter.HasNext())
            {
                if (iter.Next().Equals(item))
                {
                    contains = true;
                    break;
                }
            }

            return(contains);
        }
Ejemplo n.º 11
0
        public override string ToString()
        {
            string str = "";

            LinkedListIterator <T> iter = this.Iterator();

            while (iter.HasNext())
            {
                str += $"{iter.Next()}, ";
                if (iter.CurrentIndex >= Length)
                {
                    break;
                }
            }
            return($"[{str}]");
        }
    // Simple print method
    public static void PrintList <AnyType>(LinkedList <AnyType> theList)
    {
        if (theList.IsEmpty( ))
        {
            Console.WriteLine("Empty list");
        }
        else
        {
            LinkedListIterator <AnyType> itr = theList.First( );

            for ( ; itr.IsValid( ); itr.Advance( ))
            {
                Console.Write(itr.Retrieve( ) + " ");
            }
        }

        Console.WriteLine( );
    }
Ejemplo n.º 13
0
        // ******************************** //
        //		Private Helper Methods		//
        // ******************************** //
        /// <summary>
        /// Gets a node on an index;
        /// </summary>
        /// <param name="index">index of node to get.</param>
        /// <returns></returns>
        private Node GetNode(int index)
        {
            if (index > Length)
            {
                throw new IndexOutOfRangeException();
            }
            LinkedListIterator <T> itr = Iterator();

            while (index >= itr.CurrentIndex)
            {
                if (!itr.HasNext())
                {
                    throw new IndexOutOfRangeException();
                }
                else
                {
                    itr.Next();
                }
            }
            return(itr.CurrentNode);
        }
Ejemplo n.º 14
0
        public void FilledList_NavigateForwardAndRemoval()
        {
            var list = new LinkedList<int>();
            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);
            var iter = new LinkedListIterator<int>(list);

            Assert.AreEqual(3, list.Count);

            Assert.IsTrue(iter.hasNext());
            Assert.AreEqual(1, iter.next());
            iter.remove();
            Assert.IsTrue(iter.hasNext());
            Assert.AreEqual(2, iter.next());
            Assert.IsTrue(iter.hasNext());
            Assert.AreEqual(3, iter.next());

            Assert.AreEqual(2, list.Count);

            AssertEndOfListHasBeenReached(iter);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Iterator <int> collection1 = new LinkedListIterator <int>(new Node <int>(1, new Node <int>(2, new Node <int>(3, new Empty <int>()))));

            PrintCollection(collection1);

            Iterator <int> collection2 = new ArrayIterator <int>(new int[] { 9, 10, 11, -1 });

            PrintCollection(collection2);

            int[][] tmp_collection3 = new int[3][];
            tmp_collection3[0] = new int[] { 3, 2, 1 };
            tmp_collection3[1] = new int[] { 2, 1, 3 };
            tmp_collection3[2] = new int[] { 1, 3, 2 };
            Iterator <int> collection3 = new MatrixIterator <int>(tmp_collection3, 3, 3);

            PrintCollection(collection3);

            Iterator <int> collection4 = new NaturalNumbers();

            PrintCollection(collection4);
        }
Ejemplo n.º 16
0
        public void Set(int index, T item)
        {
            if (index > Length || index < 0)
            {
                throw new IndexOutOfRangeException();
            }

            Node newNode = new Node(item);
            LinkedListIterator <T> iterator = this.Iterator();

            if (index == 0)
            {
                // empty linked list
                if (!iterator.HasNext())
                {
                    HeaderNode.Next = newNode;
                    TailNode        = newNode;
                }
                else                 // Add newNode to first item
                {
                    newNode.Next    = HeaderNode.Next;
                    HeaderNode.Next = newNode;
                }
            }
            else if (index == Length)
            {
                Push(item);
            }
            // Add item somewhere in the middle.
            else
            {
                while (iterator.HasNext() && iterator.CurrentIndex < index)
                {
                    iterator.Next();
                }
                iterator.Data = item;
            }
        }
Ejemplo n.º 17
0
        public void FilledList_NavigateForwardAndRemoval()
        {
            var list = new LinkedList <int>();

            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);
            var iter = new LinkedListIterator <int>(list);

            Assert.AreEqual(3, list.Count);

            Assert.IsTrue(iter.hasNext());
            Assert.AreEqual(1, iter.next());
            iter.remove();
            Assert.IsTrue(iter.hasNext());
            Assert.AreEqual(2, iter.next());
            Assert.IsTrue(iter.hasNext());
            Assert.AreEqual(3, iter.next());

            Assert.AreEqual(2, list.Count);

            AssertEndOfListHasBeenReached(iter);
        }
Ejemplo n.º 18
0
 private static void AssertEndOfListHasBeenReached(LinkedListIterator<int> iter)
 {
     Assert.IsFalse(iter.hasNext());
     AssertHelper.Throws<IndexOutOfRangeException>(() => iter.next());
 }
Ejemplo n.º 19
0
        private bool DownloadPackedObject(ProgressMonitor monitor, AnyObjectId id)
        {
            // Search for the object in a remote pack whose index we have,
            // but whose pack we do not yet have.
            //
            var iter = new LinkedListIterator<RemotePack>(_unfetchedPacks);

            while (iter.hasNext() && !monitor.IsCancelled)
            {
                RemotePack pack = iter.next();
                try
                {
                    pack.OpenIndex(monitor);
                }
                catch (IOException err)
                {
                    // If the index won't open its either not found or
                    // its a format we don't recognize. In either case
                    // we may still be able to obtain the object from
                    // another source, so don't consider it a failure.
                    //
                    RecordError(id, err);
                    iter.remove();
                    continue;
                }

                if (monitor.IsCancelled)
                {
                    // If we were cancelled while the index was opening
                    // the open may have aborted. We can't search an
                    // unopen index.
                    //
                    return false;
                }

                if (!pack.Index.HasObject(id))
                {
                    // Not in this pack? Try another.
                    //
                    continue;
                }

                // It should be in the associated pack. Download that
                // and attach it to the local repository so we can use
                // all of the contained objects.
                //
                try
                {
                    pack.DownloadPack(monitor);
                }
                catch (IOException err)
                {
                    // If the pack failed to download, index correctly,
                    // or open in the local repository we may still be
                    // able to obtain this object from another pack or
                    // an alternate.
                    //
                    RecordError(id, err);
                    continue;
                }
                finally
                {
                    // If the pack was good its in the local repository
                    // and Repository.hasObject(id) will succeed in the
                    // future, so we do not need this data anymore. If
                    // it failed the index and pack are unusable and we
                    // shouldn't consult them again.
                    //
                    pack.TmpIdx.DeleteFile();
                    iter.remove();
                }

                if (!_local.HasObject(id))
                {
                    // What the hell? This pack claimed to have
                    // the object, but after indexing we didn't
                    // actually find it in the pack.
                    //
                    RecordError(id,
                                new FileNotFoundException("Object " + id.Name + " not found in " + pack.PackName + "."));
                    continue;
                }

                // Complete any other objects that we can.
                //
                IIterator<ObjectId> pending = SwapFetchQueue();
                while (pending.hasNext())
                {
                    ObjectId p = pending.next();
                    if (pack.Index.HasObject(p))
                    {
                        pending.remove();
                        Process(p);
                    }
                    else
                        _workQueue.AddLast(p);
                }
                return true;
            }
            return false;
        }
Ejemplo n.º 20
0
 private IIterator<ObjectId> SwapFetchQueue()
 {
     var r = new LinkedListIterator<ObjectId>(_workQueue);
     _workQueue = new LinkedList<ObjectId>();
     return r;
 }
        public override void Close()
        {
            IOException err = null;

            for (var i = new LinkedListIterator<Stream>(_streams); i.hasNext(); )
            {
                try
                {
                    i.next().Dispose();
                }
                catch (IOException closeError)
                {
                    err = closeError;
                }
                i.remove();
            }

            if (err != null)
                throw err;
        }
Ejemplo n.º 22
0
 private static void AssertEndOfListHasBeenReached(LinkedListIterator <int> iter)
 {
     Assert.IsFalse(iter.hasNext());
     AssertHelper.Throws <IndexOutOfRangeException>(() => iter.next());
 }
        private bool DownloadPackedObject(ProgressMonitor monitor, AnyObjectId id)
        {
            // Search for the object in a remote pack whose index we have,
            // but whose pack we do not yet have.
            //
            var iter = new LinkedListIterator <RemotePack>(_unfetchedPacks);

            while (iter.hasNext() && !monitor.IsCancelled)
            {
                RemotePack pack = iter.next();
                try
                {
                    pack.OpenIndex(monitor);
                }
                catch (IOException err)
                {
                    // If the index won't open its either not found or
                    // its a format we don't recognize. In either case
                    // we may still be able to obtain the object from
                    // another source, so don't consider it a failure.
                    //
                    RecordError(id, err);
                    iter.remove();
                    continue;
                }

                if (monitor.IsCancelled)
                {
                    // If we were cancelled while the index was opening
                    // the open may have aborted. We can't search an
                    // unopen index.
                    //
                    return(false);
                }

                if (!pack.Index.HasObject(id))
                {
                    // Not in this pack? Try another.
                    //
                    continue;
                }

                // It should be in the associated pack. Download that
                // and attach it to the local repository so we can use
                // all of the contained objects.
                //
                try
                {
                    pack.DownloadPack(monitor);
                }
                catch (IOException err)
                {
                    // If the pack failed to download, index correctly,
                    // or open in the local repository we may still be
                    // able to obtain this object from another pack or
                    // an alternate.
                    //
                    RecordError(id, err);
                    continue;
                }
                finally
                {
                    // If the pack was good its in the local repository
                    // and Repository.hasObject(id) will succeed in the
                    // future, so we do not need this data anymore. If
                    // it failed the index and pack are unusable and we
                    // shouldn't consult them again.
                    //
                    pack.TmpIdx.DeleteFile();
                    iter.remove();
                }

                if (!_local.HasObject(id))
                {
                    // What the hell? This pack claimed to have
                    // the object, but after indexing we didn't
                    // actually find it in the pack.
                    //
                    RecordError(id,
                                new FileNotFoundException("Object " + id.Name + " not found in " + pack.PackName + "."));
                    continue;
                }

                // Complete any other objects that we can.
                //
                IIterator <ObjectId> pending = SwapFetchQueue();
                while (pending.hasNext())
                {
                    ObjectId p = pending.next();
                    if (pack.Index.HasObject(p))
                    {
                        pending.remove();
                        Process(p);
                    }
                    else
                    {
                        _workQueue.AddLast(p);
                    }
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 24
0
 public TimerScheduler()
 {
     _m = new Dictionary <Timer, LinkedListNode <Timer> >();
     _s = new LinkedList <Timer>();
     _i = new LinkedListIterator <Timer>(this, _s);
 }
Ejemplo n.º 25
0
        private void handleFileSwap(LinkedListIterator<FileSystemEventArgs> renameIterator, LinkedListIterator<FileSystemEventArgs> deleteIterator)
        {
            FileSystemEventArgs delete = deleteIterator.Current;
            Utils.LinkedListIterator<FileSystemEventArgs> innerIterator = renameIterator.Clone();
            while (innerIterator.hasNext())
            {
                FileSystemEventArgs nextChange = innerIterator.Next();
                if(nextChange == delete) {
                    return;
                }
                RenamedEventArgs erlierRename = renameIterator.Current as RenamedEventArgs;
                RenamedEventArgs rename = nextChange as RenamedEventArgs;
                if (rename != null && Object.Equals(erlierRename.OldFullPath, rename.FullPath))
                {
                    //this is a file swap!
                    renameIterator.Remove();
                    innerIterator.Remove();
                    deleteIterator.Current = new FileSystemEventArgs(
                        WatcherChangeTypes.Changed,
                        Path.GetDirectoryName(erlierRename.OldFullPath),
                        Path.GetFileName(erlierRename.OldFullPath));

                    //remove any events related to temporary swap file (rename.OldFullPath)
                    string tmpFileFullPath = rename.OldFullPath;
                    Utils.LinkedListIterator<FileSystemEventArgs> tmpIterator = renameIterator.Clone();
                    while (tmpIterator.HasPrevious())
                    {
                        FileSystemEventArgs e = tmpIterator.Previous();
                        if(Object.Equals(e.FullPath, tmpFileFullPath))
                        {
                            if(e.ChangeType == WatcherChangeTypes.Renamed){
                                handleRenamed(tmpIterator);
                                if (tmpIterator.Current != null && tmpIterator.Current.ChangeType == WatcherChangeTypes.Renamed)
                                {
                                    tmpFileFullPath = ((RenamedEventArgs)tmpIterator.Current).OldFullPath;
                                }
                            }
                            if (tmpIterator.Current != null)
                            {
                                tmpIterator.Remove();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
 // Insert after p.
 // x is the item to insert.
 // p is this parameter is ignored.
 public override void Insert(AnyType x, LinkedListIterator <AnyType> p)
 {
     Insert(x);
 }
Ejemplo n.º 27
0
 public EventLooper()
 {
     locker   = new Locker();
     iterator = new LinkedListIterator <Event>(this, events);
 }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            ICustomCollection <Hero> zone1List = generateZone1();
            ICustomCollection <Hero> zone2List = generateZone2();
            ICustomCollection <Hero> zone3List = generateZone3();

            Console.WriteLine("\n\n--------- First list---------\n\n");

            IEnumerable <Hero> linkedListIterator = new LinkedListIterator(zone1List);

            foreach (var item in linkedListIterator)
            {
                Console.WriteLine($"Name: {item.HeroName}, Class: {item.HeroClass}");
            }

            Console.WriteLine("\n\n--------- Second list---------\n\n");

            IEnumerable <Hero> reversedListIterator = new ReversedArrayListIterator(zone2List);

            foreach (var item in reversedListIterator)
            {
                Console.WriteLine($"Name: {item.HeroName}, Class: {item.HeroClass}");
            }


            Console.WriteLine("\n\n--------- Concatenated list: PvP pairs ---------\n\n");

            var concatenatedList = linkedListIterator.Concat(reversedListIterator);

            /*
             *
             * foreach (var item in concatenatedList)
             * {
             *  foreach(var item2 in concatenatedList)
             *  {
             *      Console.Write($"{{{item.HeroName}, {item2.HeroName}}}\t");
             *  }
             *
             *  Console.WriteLine();
             *  Console.WriteLine();
             * }
             *
             */

            Console.WriteLine("\n\n--------- Concrete hero class linked list ---------\n\n");

            var heroClassIterator = new HeroClassIterator(linkedListIterator, HeroClass.Mage);

            foreach (var item in heroClassIterator)
            {
                Console.WriteLine($"{item.HeroClass} hero: {item.HeroName}");
            }

            Console.WriteLine("\n\n--------- Concrete hero class array list ---------\n\n");

            var heroClassArrayListIterator = new HeroClassIterator(reversedListIterator, HeroClass.Mage);

            foreach (var item in heroClassArrayListIterator)
            {
                Console.WriteLine($"{item.HeroClass} hero: {item.HeroName}");
            }
        }