private bool AppendFilter(ICConsoleViewFilter filter) { CConsoleViewCellEntry[] entriesArray = Entries.InternalArray; int toIndex = m_filteredIndices.HeadIndex; for (int fromIndex = toIndex; fromIndex < m_filteredIndices.Length; ++fromIndex) { int entryIndex = m_filteredIndices[fromIndex]; int entryArrayIndex = Entries.ToArrayIndex(entryIndex); if (filter.Apply(ref entriesArray[entryArrayIndex])) { m_filteredIndices[toIndex] = entryIndex; ++toIndex; } } // TODO: check filtered indices values (indices count can remain the same but lines can change) m_oldConsoleEntriesHeadIndex = Entries.HeadIndex; if (toIndex != m_filteredIndices.Length) { m_filteredIndices.TrimToLength(toIndex); return(true); } return(false); }
public void TestTrimLength() { CCycleArray <int> array = new CCycleArray <int>(5); array.Add(1); array.Add(2); array.Add(3); array.Add(4); array.Add(5); array.TrimToLength(3); AssertArray(array, 1, 2, 3); Assert.AreEqual(0, array.HeadIndex); Assert.AreEqual(3, array.Length); Assert.AreEqual(3, array.RealLength); array.Add(6); array.Add(7); AssertArray(array, 1, 2, 3, 6, 7); Assert.AreEqual(0, array.HeadIndex); Assert.AreEqual(5, array.Length); Assert.AreEqual(5, array.RealLength); array.Add(8); array.Add(9); AssertArray(array, 3, 6, 7, 8, 9); Assert.AreEqual(2, array.HeadIndex); Assert.AreEqual(7, array.Length); Assert.AreEqual(5, array.RealLength); array.TrimToLength(4); AssertArray(array, 3, 6); Assert.AreEqual(2, array.HeadIndex); Assert.AreEqual(4, array.Length); Assert.AreEqual(2, array.RealLength); array.Add(10); array.Add(11); AssertArray(array, 3, 6, 10, 11); Assert.AreEqual(2, array.HeadIndex); Assert.AreEqual(6, array.Length); Assert.AreEqual(4, array.RealLength); array.TrimToLength(2); AssertArray(array); Assert.AreEqual(2, array.HeadIndex); Assert.AreEqual(2, array.Length); Assert.AreEqual(0, array.RealLength); array.Add(12); array.Add(13); array.Add(14); array.Add(15); array.Add(16); array.Add(17); array.Add(18); AssertArray(array, 14, 15, 16, 17, 18); Assert.AreEqual(4, array.HeadIndex); Assert.AreEqual(9, array.Length); Assert.AreEqual(5, array.RealLength); }