/// <summary>
        ///     Removes all items from the given cell.
        ///     If the items don't occupy another cell, they are removed as well.
        /// </summary>
        /// <param name="cell">The cell to remove items from</param>
        public void Remove(Point cell)
        {
            lock (lockObject)
            {
                Point    c = Clamp(cell);
                List <T> l;
                Grid.TryGetValue(c, out l);

                if (l != null)
                {
                    foreach (T i in l)
                    {
                        List <Point> pl;
                        ItemDictionary.TryGetValue(i, out pl);
                        if (pl != null)
                        {
                            pl.Remove(c);
                            if (pl.Count == 0)
                            {
                                ListOfPointQueue.Enqueue(pl);
                                ItemDictionary.Remove(i);
                            }
                        }
                    }
                    l.Clear();
                    ListOfItemQueue.Enqueue(l);
                    Grid.Remove(cell);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1" />.
 /// </summary>
 /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
 /// <returns>true if <paramref name="item" /> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />.</returns>
 public bool Remove(TItem item)
 {
     if (HasKey)
     {
         ItemDictionary.Remove(ExtractKey(item));
     }
     ++m_VersionTag;
     return(ItemList.Remove(item));
 }
예제 #3
0
        /// <summary>
        /// Removes the <see cref="T:System.Collections.Generic.IList`1" /> item at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the item to remove.</param>
        public void RemoveAt(int index)
        {
            var item = ItemList[index];

            ++m_VersionTag;

            if (HasKey)
            {
                ItemDictionary.Remove(ExtractKey(item));
            }
            ItemList.RemoveAt(index);
        }
예제 #4
0
        /// <summary>
        /// Gets or Sets the element at the specified index in the list.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>TItem.</returns>
        public new TItem this[int index]
        {
            get { return(ItemList[index]); }
            set
            {
                var existing = ItemList[index];
                ItemList[index] = value;
                ++m_VersionTag;

                if (HasKey)
                {
                    ItemDictionary.Remove(ExtractKey(existing));
                    ItemDictionary.Add(ExtractKey(value), value);
                }
            }
        }
        /// <summary>
        ///     Removes the given item from the grid.
        /// </summary>
        /// <param name="item">The item to remove</param>
        public void Remove(T item)
        {
            lock (lockObject)
            {
                List <Point> pl;
                ItemDictionary.TryGetValue(item, out pl);
                if (pl == null)
                {
                    return;
                }

                foreach (Point p in pl)
                {
                    RemoveFromGrid(item, p);
                }

                pl.Clear();
                ListOfPointQueue.Enqueue(pl);
                ItemDictionary.Remove(item);
            }
        }
예제 #6
0
        public void BasicItemDictionary()
        {
            ItemDictionary <ProjectItemInstance> items = new ItemDictionary <ProjectItemInstance>();

            // Clearing empty collection
            items.Clear();

            // Enumeration of empty collection
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                enumerator.MoveNext().ShouldBeFalse();
                Should.Throw <InvalidOperationException>(() =>
                {
                    object o = ((IEnumerator)enumerator).Current;
                });
                enumerator.Current.ShouldBeNull();
            }

            List <ProjectItemInstance> list = new List <ProjectItemInstance>();

            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Empty(list);

            // Cause an empty list for type 'x' to be added
            ICollection <ProjectItemInstance> itemList = items["x"];

            // Enumerate empty collection, with an empty list in it
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Empty(list);

            // Add and remove some items
            ProjectItemInstance item1 = GetItemInstance("i", "i1");

            Assert.False(items.Remove(item1));
            Assert.Empty(items["j"]);

            items.Add(item1);
            Assert.Single(items["i"]);
            Assert.Equal(item1, items["i"].First());

            ProjectItemInstance item2 = GetItemInstance("i", "i2");

            items.Add(item2);
            ProjectItemInstance item3 = GetItemInstance("j", "j1");

            items.Add(item3);

            // Enumerate to verify contents
            list = new List <ProjectItemInstance>();
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            list.Sort(ProjectItemInstanceComparer);
            Assert.Equal(item1, list[0]);
            Assert.Equal(item2, list[1]);
            Assert.Equal(item3, list[2]);

            // Direct operations on the enumerator
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                Assert.Null(enumerator.Current);
                Assert.True(enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
                enumerator.Reset();
                Assert.Null(enumerator.Current);
                Assert.True(enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
            }
        }
예제 #7
0
        public void BasicItemDictionary()
        {
            ItemDictionary <ProjectItemInstance> items = new ItemDictionary <ProjectItemInstance>();

            // Clearing empty collection
            items.Clear();

            // Enumeration of empty collection
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                Assert.Equal(false, enumerator.MoveNext());
                ObjectModelHelpers.AssertThrows(typeof(InvalidOperationException), delegate { object o = ((IEnumerator)enumerator).Current; });
                Assert.Equal(null, enumerator.Current);
            }

            List <ProjectItemInstance> list = new List <ProjectItemInstance>();

            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Equal(0, list.Count);

            // Cause an empty list for type 'x' to be added
            ICollection <ProjectItemInstance> itemList = items["x"];

            // Enumerate empty collection, with an empty list in it
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Equal(0, list.Count);

            // Add and remove some items
            ProjectItemInstance item1 = GetItemInstance("i", "i1");

            Assert.Equal(false, items.Remove(item1));
            Assert.Equal(0, items["j"].Count);

            items.Add(item1);
            Assert.Equal(1, items["i"].Count);
            Assert.Equal(item1, items["i"].First());

            ProjectItemInstance item2 = GetItemInstance("i", "i2");

            items.Add(item2);
            ProjectItemInstance item3 = GetItemInstance("j", "j1");

            items.Add(item3);

            // Enumerate to verify contents
            list = new List <ProjectItemInstance>();
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            list.Sort(ProjectItemInstanceComparer);
            Assert.Equal(item1, list[0]);
            Assert.Equal(item2, list[1]);
            Assert.Equal(item3, list[2]);

            // Direct operations on the enumerator
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                Assert.Equal(null, enumerator.Current);
                Assert.Equal(true, enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
                enumerator.Reset();
                Assert.Equal(null, enumerator.Current);
                Assert.Equal(true, enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
            }
        }