예제 #1
0
        public virtual void TestFillTo0()
        {
            IntList i = new IntList();

            i.FillTo(0, int.MinValue);
            NUnit.Framework.Assert.AreEqual(0, i.Size());
        }
예제 #2
0
        public virtual void TestFillTo100()
        {
            IntList i = new IntList();

            i.FillTo(100, int.MinValue);
            NUnit.Framework.Assert.AreEqual(100, i.Size());
            i.Add(3);
            NUnit.Framework.Assert.AreEqual(int.MinValue, i.Get(99));
            NUnit.Framework.Assert.AreEqual(3, i.Get(100));
        }
예제 #3
0
        /// <summary>Index the region between <code>[ptr, end)</code> to find line starts.</summary>
        /// <remarks>
        /// Index the region between <code>[ptr, end)</code> to find line starts.
        /// <p>
        /// The returned list is 1 indexed. Index 0 contains
        /// <see cref="int.MinValue">int.MinValue</see>
        /// to pad the list out.
        /// <p>
        /// Using a 1 indexed list means that line numbers can be directly accessed
        /// from the list, so <code>list.get(1)</code> (aka get line 1) returns
        /// <code>ptr</code>.
        /// <p>
        /// The last element (index <code>map.size()-1</code>) always contains
        /// <code>end</code>.
        /// </remarks>
        /// <param name="buf">buffer to scan.</param>
        /// <param name="ptr">
        /// position within the buffer corresponding to the first byte of
        /// line 1.
        /// </param>
        /// <param name="end">1 past the end of the content within <code>buf</code>.</param>
        /// <returns>a line map indexing the start position of each line.</returns>
        public static IntList LineMap(byte[] buf, int ptr, int end)
        {
            // Experimentally derived from multiple source repositories
            // the average number of bytes/line is 36. Its a rough guess
            // to initially size our map close to the target.
            //
            IntList map = new IntList((end - ptr) / 36);

            map.FillTo(1, int.MinValue);
            for (; ptr < end; ptr = NextLF(buf, ptr))
            {
                map.Add(ptr);
            }
            map.Add(end);
            return(map);
        }
예제 #4
0
		/// <summary>Index the region between <code>[ptr, end)</code> to find line starts.</summary>
		/// <remarks>
		/// Index the region between <code>[ptr, end)</code> to find line starts.
		/// <p>
		/// The returned list is 1 indexed. Index 0 contains
		/// <see cref="int.MinValue">int.MinValue</see>
		/// to pad the list out.
		/// <p>
		/// Using a 1 indexed list means that line numbers can be directly accessed
		/// from the list, so <code>list.get(1)</code> (aka get line 1) returns
		/// <code>ptr</code>.
		/// <p>
		/// The last element (index <code>map.size()-1</code>) always contains
		/// <code>end</code>.
		/// </remarks>
		/// <param name="buf">buffer to scan.</param>
		/// <param name="ptr">
		/// position within the buffer corresponding to the first byte of
		/// line 1.
		/// </param>
		/// <param name="end">1 past the end of the content within <code>buf</code>.</param>
		/// <returns>a line map indexing the start position of each line.</returns>
		public static IntList LineMap(byte[] buf, int ptr, int end)
		{
			// Experimentally derived from multiple source repositories
			// the average number of bytes/line is 36. Its a rough guess
			// to initially size our map close to the target.
			//
			IntList map = new IntList((end - ptr) / 36);
			map.FillTo(1, int.MinValue);
			for (; ptr < end; ptr = NextLF(buf, ptr))
			{
				map.Add(ptr);
			}
			map.Add(end);
			return map;
		}
예제 #5
0
		public virtual void TestFillTo100()
		{
			IntList i = new IntList();
			i.FillTo(100, int.MinValue);
			NUnit.Framework.Assert.AreEqual(100, i.Size());
			i.Add(3);
			NUnit.Framework.Assert.AreEqual(int.MinValue, i.Get(99));
			NUnit.Framework.Assert.AreEqual(3, i.Get(100));
		}
예제 #6
0
		public virtual void TestFillTo0()
		{
			IntList i = new IntList();
			i.FillTo(0, int.MinValue);
			NUnit.Framework.Assert.AreEqual(0, i.Size());
		}